super.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609
  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.Cox@linux.org>, 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 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 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 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. * Set the port number in an address. Be agnostic about the address family.
  587. */
  588. static void nfs_set_port(struct sockaddr *sap, unsigned short port)
  589. {
  590. switch (sap->sa_family) {
  591. case AF_INET: {
  592. struct sockaddr_in *ap = (struct sockaddr_in *)sap;
  593. ap->sin_port = htons(port);
  594. break;
  595. }
  596. case AF_INET6: {
  597. struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
  598. ap->sin6_port = htons(port);
  599. break;
  600. }
  601. }
  602. }
  603. /*
  604. * Sanity-check a server address provided by the mount command.
  605. *
  606. * Address family must be initialized, and address must not be
  607. * the ANY address for that family.
  608. */
  609. static int nfs_verify_server_address(struct sockaddr *addr)
  610. {
  611. switch (addr->sa_family) {
  612. case AF_INET: {
  613. struct sockaddr_in *sa = (struct sockaddr_in *)addr;
  614. return sa->sin_addr.s_addr != htonl(INADDR_ANY);
  615. }
  616. case AF_INET6: {
  617. struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
  618. return !ipv6_addr_any(sa);
  619. }
  620. }
  621. return 0;
  622. }
  623. static void nfs_parse_ipv4_address(char *string, size_t str_len,
  624. struct sockaddr *sap, size_t *addr_len)
  625. {
  626. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  627. u8 *addr = (u8 *)&sin->sin_addr.s_addr;
  628. if (str_len <= INET_ADDRSTRLEN) {
  629. dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
  630. (int)str_len, string);
  631. sin->sin_family = AF_INET;
  632. *addr_len = sizeof(*sin);
  633. if (in4_pton(string, str_len, addr, '\0', NULL))
  634. return;
  635. }
  636. sap->sa_family = AF_UNSPEC;
  637. *addr_len = 0;
  638. }
  639. #define IPV6_SCOPE_DELIMITER '%'
  640. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  641. static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
  642. const char *delim,
  643. struct sockaddr_in6 *sin6)
  644. {
  645. char *p;
  646. size_t len;
  647. if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
  648. return ;
  649. if (*delim != IPV6_SCOPE_DELIMITER)
  650. return;
  651. len = (string + str_len) - delim - 1;
  652. p = kstrndup(delim + 1, len, GFP_KERNEL);
  653. if (p) {
  654. unsigned long scope_id = 0;
  655. struct net_device *dev;
  656. dev = dev_get_by_name(&init_net, p);
  657. if (dev != NULL) {
  658. scope_id = dev->ifindex;
  659. dev_put(dev);
  660. } else {
  661. /* scope_id is set to zero on error */
  662. strict_strtoul(p, 10, &scope_id);
  663. }
  664. kfree(p);
  665. sin6->sin6_scope_id = scope_id;
  666. dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
  667. }
  668. }
  669. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  670. struct sockaddr *sap, size_t *addr_len)
  671. {
  672. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  673. u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
  674. const char *delim;
  675. if (str_len <= INET6_ADDRSTRLEN) {
  676. dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
  677. (int)str_len, string);
  678. sin6->sin6_family = AF_INET6;
  679. *addr_len = sizeof(*sin6);
  680. if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
  681. nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
  682. return;
  683. }
  684. }
  685. sap->sa_family = AF_UNSPEC;
  686. *addr_len = 0;
  687. }
  688. #else
  689. static void nfs_parse_ipv6_address(char *string, size_t str_len,
  690. struct sockaddr *sap, size_t *addr_len)
  691. {
  692. sap->sa_family = AF_UNSPEC;
  693. *addr_len = 0;
  694. }
  695. #endif
  696. /*
  697. * Construct a sockaddr based on the contents of a string that contains
  698. * an IP address in presentation format.
  699. *
  700. * If there is a problem constructing the new sockaddr, set the address
  701. * family to AF_UNSPEC.
  702. */
  703. static void nfs_parse_ip_address(char *string, size_t str_len,
  704. struct sockaddr *sap, size_t *addr_len)
  705. {
  706. unsigned int i, colons;
  707. colons = 0;
  708. for (i = 0; i < str_len; i++)
  709. if (string[i] == ':')
  710. colons++;
  711. if (colons >= 2)
  712. nfs_parse_ipv6_address(string, str_len, sap, addr_len);
  713. else
  714. nfs_parse_ipv4_address(string, str_len, sap, addr_len);
  715. }
  716. /*
  717. * Sanity check the NFS transport protocol.
  718. *
  719. */
  720. static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
  721. {
  722. switch (mnt->nfs_server.protocol) {
  723. case XPRT_TRANSPORT_UDP:
  724. case XPRT_TRANSPORT_TCP:
  725. case XPRT_TRANSPORT_RDMA:
  726. break;
  727. default:
  728. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  729. }
  730. }
  731. /*
  732. * For text based NFSv2/v3 mounts, the mount protocol transport default
  733. * settings should depend upon the specified NFS transport.
  734. */
  735. static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
  736. {
  737. nfs_validate_transport_protocol(mnt);
  738. if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
  739. mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
  740. return;
  741. switch (mnt->nfs_server.protocol) {
  742. case XPRT_TRANSPORT_UDP:
  743. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  744. break;
  745. case XPRT_TRANSPORT_TCP:
  746. case XPRT_TRANSPORT_RDMA:
  747. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  748. }
  749. }
  750. /*
  751. * Parse the value of the 'sec=' option.
  752. *
  753. * The flavor_len setting is for v4 mounts.
  754. */
  755. static int nfs_parse_security_flavors(char *value,
  756. struct nfs_parsed_mount_data *mnt)
  757. {
  758. substring_t args[MAX_OPT_ARGS];
  759. dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
  760. switch (match_token(value, nfs_secflavor_tokens, args)) {
  761. case Opt_sec_none:
  762. mnt->auth_flavor_len = 0;
  763. mnt->auth_flavors[0] = RPC_AUTH_NULL;
  764. break;
  765. case Opt_sec_sys:
  766. mnt->auth_flavor_len = 0;
  767. mnt->auth_flavors[0] = RPC_AUTH_UNIX;
  768. break;
  769. case Opt_sec_krb5:
  770. mnt->auth_flavor_len = 1;
  771. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
  772. break;
  773. case Opt_sec_krb5i:
  774. mnt->auth_flavor_len = 1;
  775. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
  776. break;
  777. case Opt_sec_krb5p:
  778. mnt->auth_flavor_len = 1;
  779. mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
  780. break;
  781. case Opt_sec_lkey:
  782. mnt->auth_flavor_len = 1;
  783. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
  784. break;
  785. case Opt_sec_lkeyi:
  786. mnt->auth_flavor_len = 1;
  787. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
  788. break;
  789. case Opt_sec_lkeyp:
  790. mnt->auth_flavor_len = 1;
  791. mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
  792. break;
  793. case Opt_sec_spkm:
  794. mnt->auth_flavor_len = 1;
  795. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
  796. break;
  797. case Opt_sec_spkmi:
  798. mnt->auth_flavor_len = 1;
  799. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
  800. break;
  801. case Opt_sec_spkmp:
  802. mnt->auth_flavor_len = 1;
  803. mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
  804. break;
  805. default:
  806. return 0;
  807. }
  808. return 1;
  809. }
  810. static void nfs_parse_invalid_value(const char *option)
  811. {
  812. dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
  813. }
  814. /*
  815. * Error-check and convert a string of mount options from user space into
  816. * a data structure. The whole mount string is processed; bad options are
  817. * skipped as they are encountered. If there were no errors, return 1;
  818. * otherwise return 0 (zero).
  819. */
  820. static int nfs_parse_mount_options(char *raw,
  821. struct nfs_parsed_mount_data *mnt)
  822. {
  823. char *p, *string, *secdata;
  824. int rc, sloppy = 0, errors = 0;
  825. if (!raw) {
  826. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  827. return 1;
  828. }
  829. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  830. secdata = alloc_secdata();
  831. if (!secdata)
  832. goto out_nomem;
  833. rc = security_sb_copy_data(raw, secdata);
  834. if (rc)
  835. goto out_security_failure;
  836. rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
  837. if (rc)
  838. goto out_security_failure;
  839. free_secdata(secdata);
  840. while ((p = strsep(&raw, ",")) != NULL) {
  841. substring_t args[MAX_OPT_ARGS];
  842. int option, token;
  843. if (!*p)
  844. continue;
  845. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  846. token = match_token(p, nfs_mount_option_tokens, args);
  847. switch (token) {
  848. /*
  849. * boolean options: foo/nofoo
  850. */
  851. case Opt_soft:
  852. mnt->flags |= NFS_MOUNT_SOFT;
  853. break;
  854. case Opt_hard:
  855. mnt->flags &= ~NFS_MOUNT_SOFT;
  856. break;
  857. case Opt_posix:
  858. mnt->flags |= NFS_MOUNT_POSIX;
  859. break;
  860. case Opt_noposix:
  861. mnt->flags &= ~NFS_MOUNT_POSIX;
  862. break;
  863. case Opt_cto:
  864. mnt->flags &= ~NFS_MOUNT_NOCTO;
  865. break;
  866. case Opt_nocto:
  867. mnt->flags |= NFS_MOUNT_NOCTO;
  868. break;
  869. case Opt_ac:
  870. mnt->flags &= ~NFS_MOUNT_NOAC;
  871. break;
  872. case Opt_noac:
  873. mnt->flags |= NFS_MOUNT_NOAC;
  874. break;
  875. case Opt_lock:
  876. mnt->flags &= ~NFS_MOUNT_NONLM;
  877. break;
  878. case Opt_nolock:
  879. mnt->flags |= NFS_MOUNT_NONLM;
  880. break;
  881. case Opt_v2:
  882. mnt->flags &= ~NFS_MOUNT_VER3;
  883. break;
  884. case Opt_v3:
  885. mnt->flags |= NFS_MOUNT_VER3;
  886. break;
  887. case Opt_udp:
  888. mnt->flags &= ~NFS_MOUNT_TCP;
  889. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  890. break;
  891. case Opt_tcp:
  892. mnt->flags |= NFS_MOUNT_TCP;
  893. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  894. break;
  895. case Opt_rdma:
  896. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  897. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  898. break;
  899. case Opt_acl:
  900. mnt->flags &= ~NFS_MOUNT_NOACL;
  901. break;
  902. case Opt_noacl:
  903. mnt->flags |= NFS_MOUNT_NOACL;
  904. break;
  905. case Opt_rdirplus:
  906. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  907. break;
  908. case Opt_nordirplus:
  909. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  910. break;
  911. case Opt_sharecache:
  912. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  913. break;
  914. case Opt_nosharecache:
  915. mnt->flags |= NFS_MOUNT_UNSHARED;
  916. break;
  917. /*
  918. * options that take numeric values
  919. */
  920. case Opt_port:
  921. if (match_int(args, &option) ||
  922. option < 0 || option > USHORT_MAX) {
  923. errors++;
  924. nfs_parse_invalid_value("port");
  925. } else
  926. mnt->nfs_server.port = option;
  927. break;
  928. case Opt_rsize:
  929. if (match_int(args, &option) || option < 0) {
  930. errors++;
  931. nfs_parse_invalid_value("rsize");
  932. } else
  933. mnt->rsize = option;
  934. break;
  935. case Opt_wsize:
  936. if (match_int(args, &option) || option < 0) {
  937. errors++;
  938. nfs_parse_invalid_value("wsize");
  939. } else
  940. mnt->wsize = option;
  941. break;
  942. case Opt_bsize:
  943. if (match_int(args, &option) || option < 0) {
  944. errors++;
  945. nfs_parse_invalid_value("bsize");
  946. } else
  947. mnt->bsize = option;
  948. break;
  949. case Opt_timeo:
  950. if (match_int(args, &option) || option <= 0) {
  951. errors++;
  952. nfs_parse_invalid_value("timeo");
  953. } else
  954. mnt->timeo = option;
  955. break;
  956. case Opt_retrans:
  957. if (match_int(args, &option) || option <= 0) {
  958. errors++;
  959. nfs_parse_invalid_value("retrans");
  960. } else
  961. mnt->retrans = option;
  962. break;
  963. case Opt_acregmin:
  964. if (match_int(args, &option) || option < 0) {
  965. errors++;
  966. nfs_parse_invalid_value("acregmin");
  967. } else
  968. mnt->acregmin = option;
  969. break;
  970. case Opt_acregmax:
  971. if (match_int(args, &option) || option < 0) {
  972. errors++;
  973. nfs_parse_invalid_value("acregmax");
  974. } else
  975. mnt->acregmax = option;
  976. break;
  977. case Opt_acdirmin:
  978. if (match_int(args, &option) || option < 0) {
  979. errors++;
  980. nfs_parse_invalid_value("acdirmin");
  981. } else
  982. mnt->acdirmin = option;
  983. break;
  984. case Opt_acdirmax:
  985. if (match_int(args, &option) || option < 0) {
  986. errors++;
  987. nfs_parse_invalid_value("acdirmax");
  988. } else
  989. mnt->acdirmax = option;
  990. break;
  991. case Opt_actimeo:
  992. if (match_int(args, &option) || option < 0) {
  993. errors++;
  994. nfs_parse_invalid_value("actimeo");
  995. } else
  996. mnt->acregmin = mnt->acregmax =
  997. mnt->acdirmin = mnt->acdirmax = option;
  998. break;
  999. case Opt_namelen:
  1000. if (match_int(args, &option) || option < 0) {
  1001. errors++;
  1002. nfs_parse_invalid_value("namlen");
  1003. } else
  1004. mnt->namlen = option;
  1005. break;
  1006. case Opt_mountport:
  1007. if (match_int(args, &option) ||
  1008. option < 0 || option > USHORT_MAX) {
  1009. errors++;
  1010. nfs_parse_invalid_value("mountport");
  1011. } else
  1012. mnt->mount_server.port = option;
  1013. break;
  1014. case Opt_mountvers:
  1015. if (match_int(args, &option) ||
  1016. option < NFS_MNT_VERSION ||
  1017. option > NFS_MNT3_VERSION) {
  1018. errors++;
  1019. nfs_parse_invalid_value("mountvers");
  1020. } else
  1021. mnt->mount_server.version = option;
  1022. break;
  1023. case Opt_nfsvers:
  1024. if (match_int(args, &option)) {
  1025. errors++;
  1026. nfs_parse_invalid_value("nfsvers");
  1027. break;
  1028. }
  1029. switch (option) {
  1030. case NFS2_VERSION:
  1031. mnt->flags &= ~NFS_MOUNT_VER3;
  1032. break;
  1033. case NFS3_VERSION:
  1034. mnt->flags |= NFS_MOUNT_VER3;
  1035. break;
  1036. default:
  1037. errors++;
  1038. nfs_parse_invalid_value("nfsvers");
  1039. }
  1040. break;
  1041. /*
  1042. * options that take text values
  1043. */
  1044. case Opt_sec:
  1045. string = match_strdup(args);
  1046. if (string == NULL)
  1047. goto out_nomem;
  1048. rc = nfs_parse_security_flavors(string, mnt);
  1049. kfree(string);
  1050. if (!rc) {
  1051. errors++;
  1052. dfprintk(MOUNT, "NFS: unrecognized "
  1053. "security flavor\n");
  1054. }
  1055. break;
  1056. case Opt_proto:
  1057. string = match_strdup(args);
  1058. if (string == NULL)
  1059. goto out_nomem;
  1060. token = match_token(string,
  1061. nfs_xprt_protocol_tokens, args);
  1062. kfree(string);
  1063. switch (token) {
  1064. case Opt_xprt_udp:
  1065. mnt->flags &= ~NFS_MOUNT_TCP;
  1066. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1067. break;
  1068. case Opt_xprt_tcp:
  1069. mnt->flags |= NFS_MOUNT_TCP;
  1070. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1071. break;
  1072. case Opt_xprt_rdma:
  1073. /* vector side protocols to TCP */
  1074. mnt->flags |= NFS_MOUNT_TCP;
  1075. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1076. break;
  1077. default:
  1078. errors++;
  1079. dfprintk(MOUNT, "NFS: unrecognized "
  1080. "transport protocol\n");
  1081. }
  1082. break;
  1083. case Opt_mountproto:
  1084. string = match_strdup(args);
  1085. if (string == NULL)
  1086. goto out_nomem;
  1087. token = match_token(string,
  1088. nfs_xprt_protocol_tokens, args);
  1089. kfree(string);
  1090. switch (token) {
  1091. case Opt_xprt_udp:
  1092. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  1093. break;
  1094. case Opt_xprt_tcp:
  1095. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  1096. break;
  1097. case Opt_xprt_rdma: /* not used for side protocols */
  1098. default:
  1099. errors++;
  1100. dfprintk(MOUNT, "NFS: unrecognized "
  1101. "transport protocol\n");
  1102. }
  1103. break;
  1104. case Opt_addr:
  1105. string = match_strdup(args);
  1106. if (string == NULL)
  1107. goto out_nomem;
  1108. nfs_parse_ip_address(string, strlen(string),
  1109. (struct sockaddr *)
  1110. &mnt->nfs_server.address,
  1111. &mnt->nfs_server.addrlen);
  1112. kfree(string);
  1113. break;
  1114. case Opt_clientaddr:
  1115. string = match_strdup(args);
  1116. if (string == NULL)
  1117. goto out_nomem;
  1118. kfree(mnt->client_address);
  1119. mnt->client_address = string;
  1120. break;
  1121. case Opt_mounthost:
  1122. string = match_strdup(args);
  1123. if (string == NULL)
  1124. goto out_nomem;
  1125. kfree(mnt->mount_server.hostname);
  1126. mnt->mount_server.hostname = string;
  1127. break;
  1128. case Opt_mountaddr:
  1129. string = match_strdup(args);
  1130. if (string == NULL)
  1131. goto out_nomem;
  1132. nfs_parse_ip_address(string, strlen(string),
  1133. (struct sockaddr *)
  1134. &mnt->mount_server.address,
  1135. &mnt->mount_server.addrlen);
  1136. kfree(string);
  1137. break;
  1138. case Opt_lookupcache:
  1139. string = match_strdup(args);
  1140. if (string == NULL)
  1141. goto out_nomem;
  1142. token = match_token(string,
  1143. nfs_lookupcache_tokens, args);
  1144. kfree(string);
  1145. switch (token) {
  1146. case Opt_lookupcache_all:
  1147. mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
  1148. break;
  1149. case Opt_lookupcache_positive:
  1150. mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
  1151. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
  1152. break;
  1153. case Opt_lookupcache_none:
  1154. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
  1155. break;
  1156. default:
  1157. errors++;
  1158. dfprintk(MOUNT, "NFS: invalid "
  1159. "lookupcache argument\n");
  1160. };
  1161. break;
  1162. /*
  1163. * Special options
  1164. */
  1165. case Opt_sloppy:
  1166. sloppy = 1;
  1167. dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
  1168. break;
  1169. case Opt_userspace:
  1170. case Opt_deprecated:
  1171. dfprintk(MOUNT, "NFS: ignoring mount option "
  1172. "'%s'\n", p);
  1173. break;
  1174. default:
  1175. errors++;
  1176. dfprintk(MOUNT, "NFS: unrecognized mount option "
  1177. "'%s'\n", p);
  1178. }
  1179. }
  1180. if (errors > 0) {
  1181. dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
  1182. errors, (errors == 1 ? "" : "s"));
  1183. if (!sloppy)
  1184. return 0;
  1185. }
  1186. return 1;
  1187. out_nomem:
  1188. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1189. return 0;
  1190. out_security_failure:
  1191. free_secdata(secdata);
  1192. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1193. return 0;
  1194. }
  1195. /*
  1196. * Use the remote server's MOUNT service to request the NFS file handle
  1197. * corresponding to the provided path.
  1198. */
  1199. static int nfs_try_mount(struct nfs_parsed_mount_data *args,
  1200. struct nfs_fh *root_fh)
  1201. {
  1202. struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
  1203. char *hostname;
  1204. int status;
  1205. if (args->mount_server.version == 0) {
  1206. if (args->flags & NFS_MOUNT_VER3)
  1207. args->mount_server.version = NFS_MNT3_VERSION;
  1208. else
  1209. args->mount_server.version = NFS_MNT_VERSION;
  1210. }
  1211. if (args->mount_server.hostname)
  1212. hostname = args->mount_server.hostname;
  1213. else
  1214. hostname = args->nfs_server.hostname;
  1215. /*
  1216. * Construct the mount server's address.
  1217. */
  1218. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1219. memcpy(sap, &args->nfs_server.address,
  1220. args->nfs_server.addrlen);
  1221. args->mount_server.addrlen = args->nfs_server.addrlen;
  1222. }
  1223. /*
  1224. * autobind will be used if mount_server.port == 0
  1225. */
  1226. nfs_set_port(sap, args->mount_server.port);
  1227. /*
  1228. * Now ask the mount server to map our export path
  1229. * to a file handle.
  1230. */
  1231. status = nfs_mount(sap,
  1232. args->mount_server.addrlen,
  1233. hostname,
  1234. args->nfs_server.export_path,
  1235. args->mount_server.version,
  1236. args->mount_server.protocol,
  1237. root_fh);
  1238. if (status == 0)
  1239. return 0;
  1240. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1241. hostname, status);
  1242. return status;
  1243. }
  1244. static int nfs_parse_simple_hostname(const char *dev_name,
  1245. char **hostname, size_t maxnamlen,
  1246. char **export_path, size_t maxpathlen)
  1247. {
  1248. size_t len;
  1249. char *colon, *comma;
  1250. colon = strchr(dev_name, ':');
  1251. if (colon == NULL)
  1252. goto out_bad_devname;
  1253. len = colon - dev_name;
  1254. if (len > maxnamlen)
  1255. goto out_hostname;
  1256. /* N.B. caller will free nfs_server.hostname in all cases */
  1257. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1258. if (!*hostname)
  1259. goto out_nomem;
  1260. /* kill possible hostname list: not supported */
  1261. comma = strchr(*hostname, ',');
  1262. if (comma != NULL) {
  1263. if (comma == *hostname)
  1264. goto out_bad_devname;
  1265. *comma = '\0';
  1266. }
  1267. colon++;
  1268. len = strlen(colon);
  1269. if (len > maxpathlen)
  1270. goto out_path;
  1271. *export_path = kstrndup(colon, len, GFP_KERNEL);
  1272. if (!*export_path)
  1273. goto out_nomem;
  1274. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1275. return 0;
  1276. out_bad_devname:
  1277. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1278. return -EINVAL;
  1279. out_nomem:
  1280. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1281. return -ENOMEM;
  1282. out_hostname:
  1283. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1284. return -ENAMETOOLONG;
  1285. out_path:
  1286. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1287. return -ENAMETOOLONG;
  1288. }
  1289. /*
  1290. * Hostname has square brackets around it because it contains one or
  1291. * more colons. We look for the first closing square bracket, and a
  1292. * colon must follow it.
  1293. */
  1294. static int nfs_parse_protected_hostname(const char *dev_name,
  1295. char **hostname, size_t maxnamlen,
  1296. char **export_path, size_t maxpathlen)
  1297. {
  1298. size_t len;
  1299. char *start, *end;
  1300. start = (char *)(dev_name + 1);
  1301. end = strchr(start, ']');
  1302. if (end == NULL)
  1303. goto out_bad_devname;
  1304. if (*(end + 1) != ':')
  1305. goto out_bad_devname;
  1306. len = end - start;
  1307. if (len > maxnamlen)
  1308. goto out_hostname;
  1309. /* N.B. caller will free nfs_server.hostname in all cases */
  1310. *hostname = kstrndup(start, len, GFP_KERNEL);
  1311. if (*hostname == NULL)
  1312. goto out_nomem;
  1313. end += 2;
  1314. len = strlen(end);
  1315. if (len > maxpathlen)
  1316. goto out_path;
  1317. *export_path = kstrndup(end, len, GFP_KERNEL);
  1318. if (!*export_path)
  1319. goto out_nomem;
  1320. return 0;
  1321. out_bad_devname:
  1322. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1323. return -EINVAL;
  1324. out_nomem:
  1325. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1326. return -ENOMEM;
  1327. out_hostname:
  1328. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1329. return -ENAMETOOLONG;
  1330. out_path:
  1331. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1332. return -ENAMETOOLONG;
  1333. }
  1334. /*
  1335. * Split "dev_name" into "hostname:export_path".
  1336. *
  1337. * The leftmost colon demarks the split between the server's hostname
  1338. * and the export path. If the hostname starts with a left square
  1339. * bracket, then it may contain colons.
  1340. *
  1341. * Note: caller frees hostname and export path, even on error.
  1342. */
  1343. static int nfs_parse_devname(const char *dev_name,
  1344. char **hostname, size_t maxnamlen,
  1345. char **export_path, size_t maxpathlen)
  1346. {
  1347. if (*dev_name == '[')
  1348. return nfs_parse_protected_hostname(dev_name,
  1349. hostname, maxnamlen,
  1350. export_path, maxpathlen);
  1351. return nfs_parse_simple_hostname(dev_name,
  1352. hostname, maxnamlen,
  1353. export_path, maxpathlen);
  1354. }
  1355. /*
  1356. * Validate the NFS2/NFS3 mount data
  1357. * - fills in the mount root filehandle
  1358. *
  1359. * For option strings, user space handles the following behaviors:
  1360. *
  1361. * + DNS: mapping server host name to IP address ("addr=" option)
  1362. *
  1363. * + failure mode: how to behave if a mount request can't be handled
  1364. * immediately ("fg/bg" option)
  1365. *
  1366. * + retry: how often to retry a mount request ("retry=" option)
  1367. *
  1368. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1369. * mountproto=tcp after mountproto=udp, and so on
  1370. */
  1371. static int nfs_validate_mount_data(void *options,
  1372. struct nfs_parsed_mount_data *args,
  1373. struct nfs_fh *mntfh,
  1374. const char *dev_name)
  1375. {
  1376. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1377. if (data == NULL)
  1378. goto out_no_data;
  1379. args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
  1380. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1381. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1382. args->acregmin = NFS_DEF_ACREGMIN;
  1383. args->acregmax = NFS_DEF_ACREGMAX;
  1384. args->acdirmin = NFS_DEF_ACDIRMIN;
  1385. args->acdirmax = NFS_DEF_ACDIRMAX;
  1386. args->mount_server.port = 0; /* autobind unless user sets port */
  1387. args->nfs_server.port = 0; /* autobind unless user sets port */
  1388. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1389. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1390. switch (data->version) {
  1391. case 1:
  1392. data->namlen = 0;
  1393. case 2:
  1394. data->bsize = 0;
  1395. case 3:
  1396. if (data->flags & NFS_MOUNT_VER3)
  1397. goto out_no_v3;
  1398. data->root.size = NFS2_FHSIZE;
  1399. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1400. case 4:
  1401. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1402. goto out_no_sec;
  1403. case 5:
  1404. memset(data->context, 0, sizeof(data->context));
  1405. case 6:
  1406. if (data->flags & NFS_MOUNT_VER3) {
  1407. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1408. goto out_invalid_fh;
  1409. mntfh->size = data->root.size;
  1410. } else
  1411. mntfh->size = NFS2_FHSIZE;
  1412. memcpy(mntfh->data, data->root.data, mntfh->size);
  1413. if (mntfh->size < sizeof(mntfh->data))
  1414. memset(mntfh->data + mntfh->size, 0,
  1415. sizeof(mntfh->data) - mntfh->size);
  1416. /*
  1417. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1418. * can deal with.
  1419. */
  1420. args->flags = data->flags & NFS_MOUNT_FLAGMASK;
  1421. args->rsize = data->rsize;
  1422. args->wsize = data->wsize;
  1423. args->timeo = data->timeo;
  1424. args->retrans = data->retrans;
  1425. args->acregmin = data->acregmin;
  1426. args->acregmax = data->acregmax;
  1427. args->acdirmin = data->acdirmin;
  1428. args->acdirmax = data->acdirmax;
  1429. memcpy(&args->nfs_server.address, &data->addr,
  1430. sizeof(data->addr));
  1431. args->nfs_server.addrlen = sizeof(data->addr);
  1432. if (!nfs_verify_server_address((struct sockaddr *)
  1433. &args->nfs_server.address))
  1434. goto out_no_address;
  1435. if (!(data->flags & NFS_MOUNT_TCP))
  1436. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1437. /* N.B. caller will free nfs_server.hostname in all cases */
  1438. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1439. args->namlen = data->namlen;
  1440. args->bsize = data->bsize;
  1441. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1442. args->auth_flavors[0] = data->pseudoflavor;
  1443. if (!args->nfs_server.hostname)
  1444. goto out_nomem;
  1445. /*
  1446. * The legacy version 6 binary mount data from userspace has a
  1447. * field used only to transport selinux information into the
  1448. * the kernel. To continue to support that functionality we
  1449. * have a touch of selinux knowledge here in the NFS code. The
  1450. * userspace code converted context=blah to just blah so we are
  1451. * converting back to the full string selinux understands.
  1452. */
  1453. if (data->context[0]){
  1454. #ifdef CONFIG_SECURITY_SELINUX
  1455. int rc;
  1456. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1457. if (!opts_str)
  1458. return -ENOMEM;
  1459. strcpy(opts_str, "context=");
  1460. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1461. strcat(opts_str, &data->context[0]);
  1462. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1463. kfree(opts_str);
  1464. if (rc)
  1465. return rc;
  1466. #else
  1467. return -EINVAL;
  1468. #endif
  1469. }
  1470. break;
  1471. default: {
  1472. int status;
  1473. if (nfs_parse_mount_options((char *)options, args) == 0)
  1474. return -EINVAL;
  1475. if (!nfs_verify_server_address((struct sockaddr *)
  1476. &args->nfs_server.address))
  1477. goto out_no_address;
  1478. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1479. args->nfs_server.port);
  1480. nfs_set_mount_transport_protocol(args);
  1481. status = nfs_parse_devname(dev_name,
  1482. &args->nfs_server.hostname,
  1483. PAGE_SIZE,
  1484. &args->nfs_server.export_path,
  1485. NFS_MAXPATHLEN);
  1486. if (!status)
  1487. status = nfs_try_mount(args, mntfh);
  1488. kfree(args->nfs_server.export_path);
  1489. args->nfs_server.export_path = NULL;
  1490. if (status)
  1491. return status;
  1492. break;
  1493. }
  1494. }
  1495. #ifndef CONFIG_NFS_V3
  1496. if (args->flags & NFS_MOUNT_VER3)
  1497. goto out_v3_not_compiled;
  1498. #endif /* !CONFIG_NFS_V3 */
  1499. return 0;
  1500. out_no_data:
  1501. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1502. return -EINVAL;
  1503. out_no_v3:
  1504. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1505. data->version);
  1506. return -EINVAL;
  1507. out_no_sec:
  1508. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1509. return -EINVAL;
  1510. #ifndef CONFIG_NFS_V3
  1511. out_v3_not_compiled:
  1512. dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
  1513. return -EPROTONOSUPPORT;
  1514. #endif /* !CONFIG_NFS_V3 */
  1515. out_nomem:
  1516. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1517. return -ENOMEM;
  1518. out_no_address:
  1519. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1520. return -EINVAL;
  1521. out_invalid_fh:
  1522. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1523. return -EINVAL;
  1524. }
  1525. static int
  1526. nfs_compare_remount_data(struct nfs_server *nfss,
  1527. struct nfs_parsed_mount_data *data)
  1528. {
  1529. if (data->flags != nfss->flags ||
  1530. data->rsize != nfss->rsize ||
  1531. data->wsize != nfss->wsize ||
  1532. data->retrans != nfss->client->cl_timeout->to_retries ||
  1533. data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
  1534. data->acregmin != nfss->acregmin / HZ ||
  1535. data->acregmax != nfss->acregmax / HZ ||
  1536. data->acdirmin != nfss->acdirmin / HZ ||
  1537. data->acdirmax != nfss->acdirmax / HZ ||
  1538. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1539. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1540. memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1541. data->nfs_server.addrlen) != 0)
  1542. return -EINVAL;
  1543. return 0;
  1544. }
  1545. static int
  1546. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1547. {
  1548. int error;
  1549. struct nfs_server *nfss = sb->s_fs_info;
  1550. struct nfs_parsed_mount_data *data;
  1551. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1552. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1553. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1554. /*
  1555. * Userspace mount programs that send binary options generally send
  1556. * them populated with default values. We have no way to know which
  1557. * ones were explicitly specified. Fall back to legacy behavior and
  1558. * just return success.
  1559. */
  1560. if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
  1561. (nfsvers <= 3 && (!options || (options->version >= 1 &&
  1562. options->version <= 6))))
  1563. return 0;
  1564. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1565. if (data == NULL)
  1566. return -ENOMEM;
  1567. /* fill out struct with values from existing mount */
  1568. data->flags = nfss->flags;
  1569. data->rsize = nfss->rsize;
  1570. data->wsize = nfss->wsize;
  1571. data->retrans = nfss->client->cl_timeout->to_retries;
  1572. data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
  1573. data->acregmin = nfss->acregmin / HZ;
  1574. data->acregmax = nfss->acregmax / HZ;
  1575. data->acdirmin = nfss->acdirmin / HZ;
  1576. data->acdirmax = nfss->acdirmax / HZ;
  1577. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  1578. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  1579. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1580. data->nfs_server.addrlen);
  1581. /* overwrite those values with any that were specified */
  1582. error = nfs_parse_mount_options((char *)options, data);
  1583. if (error < 0)
  1584. goto out;
  1585. /* compare new mount options with old ones */
  1586. error = nfs_compare_remount_data(nfss, data);
  1587. out:
  1588. kfree(data);
  1589. return error;
  1590. }
  1591. /*
  1592. * Initialise the common bits of the superblock
  1593. */
  1594. static inline void nfs_initialise_sb(struct super_block *sb)
  1595. {
  1596. struct nfs_server *server = NFS_SB(sb);
  1597. sb->s_magic = NFS_SUPER_MAGIC;
  1598. /* We probably want something more informative here */
  1599. snprintf(sb->s_id, sizeof(sb->s_id),
  1600. "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  1601. if (sb->s_blocksize == 0)
  1602. sb->s_blocksize = nfs_block_bits(server->wsize,
  1603. &sb->s_blocksize_bits);
  1604. if (server->flags & NFS_MOUNT_NOAC)
  1605. sb->s_flags |= MS_SYNCHRONOUS;
  1606. nfs_super_set_maxbytes(sb, server->maxfilesize);
  1607. }
  1608. /*
  1609. * Finish setting up an NFS2/3 superblock
  1610. */
  1611. static void nfs_fill_super(struct super_block *sb,
  1612. struct nfs_parsed_mount_data *data)
  1613. {
  1614. struct nfs_server *server = NFS_SB(sb);
  1615. sb->s_blocksize_bits = 0;
  1616. sb->s_blocksize = 0;
  1617. if (data->bsize)
  1618. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  1619. if (server->flags & NFS_MOUNT_VER3) {
  1620. /* The VFS shouldn't apply the umask to mode bits. We will do
  1621. * so ourselves when necessary.
  1622. */
  1623. sb->s_flags |= MS_POSIXACL;
  1624. sb->s_time_gran = 1;
  1625. }
  1626. sb->s_op = &nfs_sops;
  1627. nfs_initialise_sb(sb);
  1628. }
  1629. /*
  1630. * Finish setting up a cloned NFS2/3 superblock
  1631. */
  1632. static void nfs_clone_super(struct super_block *sb,
  1633. const struct super_block *old_sb)
  1634. {
  1635. struct nfs_server *server = NFS_SB(sb);
  1636. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1637. sb->s_blocksize = old_sb->s_blocksize;
  1638. sb->s_maxbytes = old_sb->s_maxbytes;
  1639. if (server->flags & NFS_MOUNT_VER3) {
  1640. /* The VFS shouldn't apply the umask to mode bits. We will do
  1641. * so ourselves when necessary.
  1642. */
  1643. sb->s_flags |= MS_POSIXACL;
  1644. sb->s_time_gran = 1;
  1645. }
  1646. sb->s_op = old_sb->s_op;
  1647. nfs_initialise_sb(sb);
  1648. }
  1649. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  1650. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  1651. {
  1652. const struct nfs_server *a = s->s_fs_info;
  1653. const struct rpc_clnt *clnt_a = a->client;
  1654. const struct rpc_clnt *clnt_b = b->client;
  1655. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  1656. goto Ebusy;
  1657. if (a->nfs_client != b->nfs_client)
  1658. goto Ebusy;
  1659. if (a->flags != b->flags)
  1660. goto Ebusy;
  1661. if (a->wsize != b->wsize)
  1662. goto Ebusy;
  1663. if (a->rsize != b->rsize)
  1664. goto Ebusy;
  1665. if (a->acregmin != b->acregmin)
  1666. goto Ebusy;
  1667. if (a->acregmax != b->acregmax)
  1668. goto Ebusy;
  1669. if (a->acdirmin != b->acdirmin)
  1670. goto Ebusy;
  1671. if (a->acdirmax != b->acdirmax)
  1672. goto Ebusy;
  1673. if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  1674. goto Ebusy;
  1675. return 1;
  1676. Ebusy:
  1677. return 0;
  1678. }
  1679. struct nfs_sb_mountdata {
  1680. struct nfs_server *server;
  1681. int mntflags;
  1682. };
  1683. static int nfs_set_super(struct super_block *s, void *data)
  1684. {
  1685. struct nfs_sb_mountdata *sb_mntdata = data;
  1686. struct nfs_server *server = sb_mntdata->server;
  1687. int ret;
  1688. s->s_flags = sb_mntdata->mntflags;
  1689. s->s_fs_info = server;
  1690. ret = set_anon_super(s, server);
  1691. if (ret == 0)
  1692. server->s_dev = s->s_dev;
  1693. return ret;
  1694. }
  1695. static int nfs_compare_super_address(struct nfs_server *server1,
  1696. struct nfs_server *server2)
  1697. {
  1698. struct sockaddr *sap1, *sap2;
  1699. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  1700. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  1701. if (sap1->sa_family != sap2->sa_family)
  1702. return 0;
  1703. switch (sap1->sa_family) {
  1704. case AF_INET: {
  1705. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  1706. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  1707. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  1708. return 0;
  1709. if (sin1->sin_port != sin2->sin_port)
  1710. return 0;
  1711. break;
  1712. }
  1713. case AF_INET6: {
  1714. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  1715. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  1716. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  1717. return 0;
  1718. if (sin1->sin6_port != sin2->sin6_port)
  1719. return 0;
  1720. break;
  1721. }
  1722. default:
  1723. return 0;
  1724. }
  1725. return 1;
  1726. }
  1727. static int nfs_compare_super(struct super_block *sb, void *data)
  1728. {
  1729. struct nfs_sb_mountdata *sb_mntdata = data;
  1730. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  1731. int mntflags = sb_mntdata->mntflags;
  1732. if (!nfs_compare_super_address(old, server))
  1733. return 0;
  1734. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  1735. if (old->flags & NFS_MOUNT_UNSHARED)
  1736. return 0;
  1737. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  1738. return 0;
  1739. return nfs_compare_mount_options(sb, server, mntflags);
  1740. }
  1741. static int nfs_bdi_register(struct nfs_server *server)
  1742. {
  1743. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  1744. }
  1745. static int nfs_get_sb(struct file_system_type *fs_type,
  1746. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1747. {
  1748. struct nfs_server *server = NULL;
  1749. struct super_block *s;
  1750. struct nfs_parsed_mount_data *data;
  1751. struct nfs_fh *mntfh;
  1752. struct dentry *mntroot;
  1753. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1754. struct nfs_sb_mountdata sb_mntdata = {
  1755. .mntflags = flags,
  1756. };
  1757. int error = -ENOMEM;
  1758. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1759. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  1760. if (data == NULL || mntfh == NULL)
  1761. goto out_free_fh;
  1762. security_init_mnt_opts(&data->lsm_opts);
  1763. /* Validate the mount data */
  1764. error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
  1765. if (error < 0)
  1766. goto out;
  1767. /* Get a volume representation */
  1768. server = nfs_create_server(data, mntfh);
  1769. if (IS_ERR(server)) {
  1770. error = PTR_ERR(server);
  1771. goto out;
  1772. }
  1773. sb_mntdata.server = server;
  1774. if (server->flags & NFS_MOUNT_UNSHARED)
  1775. compare_super = NULL;
  1776. /* Get a superblock - note that we may end up sharing one that already exists */
  1777. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1778. if (IS_ERR(s)) {
  1779. error = PTR_ERR(s);
  1780. goto out_err_nosb;
  1781. }
  1782. if (s->s_fs_info != server) {
  1783. nfs_free_server(server);
  1784. server = NULL;
  1785. } else {
  1786. error = nfs_bdi_register(server);
  1787. if (error)
  1788. goto error_splat_super;
  1789. }
  1790. if (!s->s_root) {
  1791. /* initial superblock/root creation */
  1792. nfs_fill_super(s, data);
  1793. }
  1794. mntroot = nfs_get_root(s, mntfh);
  1795. if (IS_ERR(mntroot)) {
  1796. error = PTR_ERR(mntroot);
  1797. goto error_splat_super;
  1798. }
  1799. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  1800. if (error)
  1801. goto error_splat_root;
  1802. s->s_flags |= MS_ACTIVE;
  1803. mnt->mnt_sb = s;
  1804. mnt->mnt_root = mntroot;
  1805. error = 0;
  1806. out:
  1807. kfree(data->nfs_server.hostname);
  1808. kfree(data->mount_server.hostname);
  1809. security_free_mnt_opts(&data->lsm_opts);
  1810. out_free_fh:
  1811. kfree(mntfh);
  1812. kfree(data);
  1813. return error;
  1814. out_err_nosb:
  1815. nfs_free_server(server);
  1816. goto out;
  1817. error_splat_root:
  1818. dput(mntroot);
  1819. error_splat_super:
  1820. up_write(&s->s_umount);
  1821. deactivate_super(s);
  1822. goto out;
  1823. }
  1824. /*
  1825. * Destroy an NFS2/3 superblock
  1826. */
  1827. static void nfs_kill_super(struct super_block *s)
  1828. {
  1829. struct nfs_server *server = NFS_SB(s);
  1830. bdi_unregister(&server->backing_dev_info);
  1831. kill_anon_super(s);
  1832. nfs_free_server(server);
  1833. }
  1834. /*
  1835. * Clone an NFS2/3 server record on xdev traversal (FSID-change)
  1836. */
  1837. static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1838. const char *dev_name, void *raw_data,
  1839. struct vfsmount *mnt)
  1840. {
  1841. struct nfs_clone_mount *data = raw_data;
  1842. struct super_block *s;
  1843. struct nfs_server *server;
  1844. struct dentry *mntroot;
  1845. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1846. struct nfs_sb_mountdata sb_mntdata = {
  1847. .mntflags = flags,
  1848. };
  1849. int error;
  1850. dprintk("--> nfs_xdev_get_sb()\n");
  1851. /* create a new volume representation */
  1852. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1853. if (IS_ERR(server)) {
  1854. error = PTR_ERR(server);
  1855. goto out_err_noserver;
  1856. }
  1857. sb_mntdata.server = server;
  1858. if (server->flags & NFS_MOUNT_UNSHARED)
  1859. compare_super = NULL;
  1860. /* Get a superblock - note that we may end up sharing one that already exists */
  1861. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1862. if (IS_ERR(s)) {
  1863. error = PTR_ERR(s);
  1864. goto out_err_nosb;
  1865. }
  1866. if (s->s_fs_info != server) {
  1867. nfs_free_server(server);
  1868. server = NULL;
  1869. } else {
  1870. error = nfs_bdi_register(server);
  1871. if (error)
  1872. goto error_splat_super;
  1873. }
  1874. if (!s->s_root) {
  1875. /* initial superblock/root creation */
  1876. nfs_clone_super(s, data->sb);
  1877. }
  1878. mntroot = nfs_get_root(s, data->fh);
  1879. if (IS_ERR(mntroot)) {
  1880. error = PTR_ERR(mntroot);
  1881. goto error_splat_super;
  1882. }
  1883. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1884. dput(mntroot);
  1885. error = -ESTALE;
  1886. goto error_splat_super;
  1887. }
  1888. s->s_flags |= MS_ACTIVE;
  1889. mnt->mnt_sb = s;
  1890. mnt->mnt_root = mntroot;
  1891. /* clone any lsm security options from the parent to the new sb */
  1892. security_sb_clone_mnt_opts(data->sb, s);
  1893. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1894. return 0;
  1895. out_err_nosb:
  1896. nfs_free_server(server);
  1897. out_err_noserver:
  1898. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1899. return error;
  1900. error_splat_super:
  1901. up_write(&s->s_umount);
  1902. deactivate_super(s);
  1903. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1904. return error;
  1905. }
  1906. #ifdef CONFIG_NFS_V4
  1907. /*
  1908. * Finish setting up a cloned NFS4 superblock
  1909. */
  1910. static void nfs4_clone_super(struct super_block *sb,
  1911. const struct super_block *old_sb)
  1912. {
  1913. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1914. sb->s_blocksize = old_sb->s_blocksize;
  1915. sb->s_maxbytes = old_sb->s_maxbytes;
  1916. sb->s_time_gran = 1;
  1917. sb->s_op = old_sb->s_op;
  1918. nfs_initialise_sb(sb);
  1919. }
  1920. /*
  1921. * Set up an NFS4 superblock
  1922. */
  1923. static void nfs4_fill_super(struct super_block *sb)
  1924. {
  1925. sb->s_time_gran = 1;
  1926. sb->s_op = &nfs4_sops;
  1927. nfs_initialise_sb(sb);
  1928. }
  1929. /*
  1930. * Validate NFSv4 mount options
  1931. */
  1932. static int nfs4_validate_mount_data(void *options,
  1933. struct nfs_parsed_mount_data *args,
  1934. const char *dev_name)
  1935. {
  1936. struct sockaddr_in *ap;
  1937. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1938. char *c;
  1939. if (data == NULL)
  1940. goto out_no_data;
  1941. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1942. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1943. args->acregmin = NFS_DEF_ACREGMIN;
  1944. args->acregmax = NFS_DEF_ACREGMAX;
  1945. args->acdirmin = NFS_DEF_ACDIRMIN;
  1946. args->acdirmax = NFS_DEF_ACDIRMAX;
  1947. args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
  1948. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1949. args->auth_flavor_len = 0;
  1950. switch (data->version) {
  1951. case 1:
  1952. ap = (struct sockaddr_in *)&args->nfs_server.address;
  1953. if (data->host_addrlen > sizeof(args->nfs_server.address))
  1954. goto out_no_address;
  1955. if (data->host_addrlen == 0)
  1956. goto out_no_address;
  1957. args->nfs_server.addrlen = data->host_addrlen;
  1958. if (copy_from_user(ap, data->host_addr, data->host_addrlen))
  1959. return -EFAULT;
  1960. if (!nfs_verify_server_address((struct sockaddr *)
  1961. &args->nfs_server.address))
  1962. goto out_no_address;
  1963. if (data->auth_flavourlen) {
  1964. if (data->auth_flavourlen > 1)
  1965. goto out_inval_auth;
  1966. if (copy_from_user(&args->auth_flavors[0],
  1967. data->auth_flavours,
  1968. sizeof(args->auth_flavors[0])))
  1969. return -EFAULT;
  1970. }
  1971. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  1972. if (IS_ERR(c))
  1973. return PTR_ERR(c);
  1974. args->nfs_server.hostname = c;
  1975. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  1976. if (IS_ERR(c))
  1977. return PTR_ERR(c);
  1978. args->nfs_server.export_path = c;
  1979. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  1980. c = strndup_user(data->client_addr.data, 16);
  1981. if (IS_ERR(c))
  1982. return PTR_ERR(c);
  1983. args->client_address = c;
  1984. /*
  1985. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  1986. * can deal with.
  1987. */
  1988. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  1989. args->rsize = data->rsize;
  1990. args->wsize = data->wsize;
  1991. args->timeo = data->timeo;
  1992. args->retrans = data->retrans;
  1993. args->acregmin = data->acregmin;
  1994. args->acregmax = data->acregmax;
  1995. args->acdirmin = data->acdirmin;
  1996. args->acdirmax = data->acdirmax;
  1997. args->nfs_server.protocol = data->proto;
  1998. nfs_validate_transport_protocol(args);
  1999. break;
  2000. default: {
  2001. int status;
  2002. if (nfs_parse_mount_options((char *)options, args) == 0)
  2003. return -EINVAL;
  2004. if (!nfs_verify_server_address((struct sockaddr *)
  2005. &args->nfs_server.address))
  2006. return -EINVAL;
  2007. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  2008. args->nfs_server.port);
  2009. nfs_validate_transport_protocol(args);
  2010. if (args->auth_flavor_len > 1)
  2011. goto out_inval_auth;
  2012. if (args->client_address == NULL)
  2013. goto out_no_client_address;
  2014. status = nfs_parse_devname(dev_name,
  2015. &args->nfs_server.hostname,
  2016. NFS4_MAXNAMLEN,
  2017. &args->nfs_server.export_path,
  2018. NFS4_MAXPATHLEN);
  2019. if (status < 0)
  2020. return status;
  2021. break;
  2022. }
  2023. }
  2024. return 0;
  2025. out_no_data:
  2026. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  2027. return -EINVAL;
  2028. out_inval_auth:
  2029. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  2030. data->auth_flavourlen);
  2031. return -EINVAL;
  2032. out_no_address:
  2033. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  2034. return -EINVAL;
  2035. out_no_client_address:
  2036. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  2037. return -EINVAL;
  2038. }
  2039. /*
  2040. * Get the superblock for an NFS4 mountpoint
  2041. */
  2042. static int nfs4_get_sb(struct file_system_type *fs_type,
  2043. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  2044. {
  2045. struct nfs_parsed_mount_data *data;
  2046. struct super_block *s;
  2047. struct nfs_server *server;
  2048. struct nfs_fh *mntfh;
  2049. struct dentry *mntroot;
  2050. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2051. struct nfs_sb_mountdata sb_mntdata = {
  2052. .mntflags = flags,
  2053. };
  2054. int error = -ENOMEM;
  2055. data = kzalloc(sizeof(*data), GFP_KERNEL);
  2056. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  2057. if (data == NULL || mntfh == NULL)
  2058. goto out_free_fh;
  2059. security_init_mnt_opts(&data->lsm_opts);
  2060. /* Validate the mount data */
  2061. error = nfs4_validate_mount_data(raw_data, data, dev_name);
  2062. if (error < 0)
  2063. goto out;
  2064. /* Get a volume representation */
  2065. server = nfs4_create_server(data, mntfh);
  2066. if (IS_ERR(server)) {
  2067. error = PTR_ERR(server);
  2068. goto out;
  2069. }
  2070. sb_mntdata.server = server;
  2071. if (server->flags & NFS4_MOUNT_UNSHARED)
  2072. compare_super = NULL;
  2073. /* Get a superblock - note that we may end up sharing one that already exists */
  2074. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2075. if (IS_ERR(s)) {
  2076. error = PTR_ERR(s);
  2077. goto out_free;
  2078. }
  2079. if (s->s_fs_info != server) {
  2080. nfs_free_server(server);
  2081. server = NULL;
  2082. } else {
  2083. error = nfs_bdi_register(server);
  2084. if (error)
  2085. goto error_splat_super;
  2086. }
  2087. if (!s->s_root) {
  2088. /* initial superblock/root creation */
  2089. nfs4_fill_super(s);
  2090. }
  2091. mntroot = nfs4_get_root(s, mntfh);
  2092. if (IS_ERR(mntroot)) {
  2093. error = PTR_ERR(mntroot);
  2094. goto error_splat_super;
  2095. }
  2096. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  2097. if (error)
  2098. goto error_splat_root;
  2099. s->s_flags |= MS_ACTIVE;
  2100. mnt->mnt_sb = s;
  2101. mnt->mnt_root = mntroot;
  2102. error = 0;
  2103. out:
  2104. kfree(data->client_address);
  2105. kfree(data->nfs_server.export_path);
  2106. kfree(data->nfs_server.hostname);
  2107. security_free_mnt_opts(&data->lsm_opts);
  2108. out_free_fh:
  2109. kfree(mntfh);
  2110. kfree(data);
  2111. return error;
  2112. out_free:
  2113. nfs_free_server(server);
  2114. goto out;
  2115. error_splat_root:
  2116. dput(mntroot);
  2117. error_splat_super:
  2118. up_write(&s->s_umount);
  2119. deactivate_super(s);
  2120. goto out;
  2121. }
  2122. static void nfs4_kill_super(struct super_block *sb)
  2123. {
  2124. struct nfs_server *server = NFS_SB(sb);
  2125. nfs_return_all_delegations(sb);
  2126. kill_anon_super(sb);
  2127. nfs4_renewd_prepare_shutdown(server);
  2128. nfs_free_server(server);
  2129. }
  2130. /*
  2131. * Clone an NFS4 server record on xdev traversal (FSID-change)
  2132. */
  2133. static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
  2134. const char *dev_name, void *raw_data,
  2135. struct vfsmount *mnt)
  2136. {
  2137. struct nfs_clone_mount *data = raw_data;
  2138. struct super_block *s;
  2139. struct nfs_server *server;
  2140. struct dentry *mntroot;
  2141. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2142. struct nfs_sb_mountdata sb_mntdata = {
  2143. .mntflags = flags,
  2144. };
  2145. int error;
  2146. dprintk("--> nfs4_xdev_get_sb()\n");
  2147. /* create a new volume representation */
  2148. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  2149. if (IS_ERR(server)) {
  2150. error = PTR_ERR(server);
  2151. goto out_err_noserver;
  2152. }
  2153. sb_mntdata.server = server;
  2154. if (server->flags & NFS4_MOUNT_UNSHARED)
  2155. compare_super = NULL;
  2156. /* Get a superblock - note that we may end up sharing one that already exists */
  2157. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2158. if (IS_ERR(s)) {
  2159. error = PTR_ERR(s);
  2160. goto out_err_nosb;
  2161. }
  2162. if (s->s_fs_info != server) {
  2163. nfs_free_server(server);
  2164. server = NULL;
  2165. } else {
  2166. error = nfs_bdi_register(server);
  2167. if (error)
  2168. goto error_splat_super;
  2169. }
  2170. if (!s->s_root) {
  2171. /* initial superblock/root creation */
  2172. nfs4_clone_super(s, data->sb);
  2173. }
  2174. mntroot = nfs4_get_root(s, data->fh);
  2175. if (IS_ERR(mntroot)) {
  2176. error = PTR_ERR(mntroot);
  2177. goto error_splat_super;
  2178. }
  2179. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2180. dput(mntroot);
  2181. error = -ESTALE;
  2182. goto error_splat_super;
  2183. }
  2184. s->s_flags |= MS_ACTIVE;
  2185. mnt->mnt_sb = s;
  2186. mnt->mnt_root = mntroot;
  2187. security_sb_clone_mnt_opts(data->sb, s);
  2188. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  2189. return 0;
  2190. out_err_nosb:
  2191. nfs_free_server(server);
  2192. out_err_noserver:
  2193. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  2194. return error;
  2195. error_splat_super:
  2196. up_write(&s->s_umount);
  2197. deactivate_super(s);
  2198. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  2199. return error;
  2200. }
  2201. /*
  2202. * Create an NFS4 server record on referral traversal
  2203. */
  2204. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  2205. const char *dev_name, void *raw_data,
  2206. struct vfsmount *mnt)
  2207. {
  2208. struct nfs_clone_mount *data = raw_data;
  2209. struct super_block *s;
  2210. struct nfs_server *server;
  2211. struct dentry *mntroot;
  2212. struct nfs_fh mntfh;
  2213. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2214. struct nfs_sb_mountdata sb_mntdata = {
  2215. .mntflags = flags,
  2216. };
  2217. int error;
  2218. dprintk("--> nfs4_referral_get_sb()\n");
  2219. /* create a new volume representation */
  2220. server = nfs4_create_referral_server(data, &mntfh);
  2221. if (IS_ERR(server)) {
  2222. error = PTR_ERR(server);
  2223. goto out_err_noserver;
  2224. }
  2225. sb_mntdata.server = server;
  2226. if (server->flags & NFS4_MOUNT_UNSHARED)
  2227. compare_super = NULL;
  2228. /* Get a superblock - note that we may end up sharing one that already exists */
  2229. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2230. if (IS_ERR(s)) {
  2231. error = PTR_ERR(s);
  2232. goto out_err_nosb;
  2233. }
  2234. if (s->s_fs_info != server) {
  2235. nfs_free_server(server);
  2236. server = NULL;
  2237. } else {
  2238. error = nfs_bdi_register(server);
  2239. if (error)
  2240. goto error_splat_super;
  2241. }
  2242. if (!s->s_root) {
  2243. /* initial superblock/root creation */
  2244. nfs4_fill_super(s);
  2245. }
  2246. mntroot = nfs4_get_root(s, &mntfh);
  2247. if (IS_ERR(mntroot)) {
  2248. error = PTR_ERR(mntroot);
  2249. goto error_splat_super;
  2250. }
  2251. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2252. dput(mntroot);
  2253. error = -ESTALE;
  2254. goto error_splat_super;
  2255. }
  2256. s->s_flags |= MS_ACTIVE;
  2257. mnt->mnt_sb = s;
  2258. mnt->mnt_root = mntroot;
  2259. security_sb_clone_mnt_opts(data->sb, s);
  2260. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  2261. return 0;
  2262. out_err_nosb:
  2263. nfs_free_server(server);
  2264. out_err_noserver:
  2265. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  2266. return error;
  2267. error_splat_super:
  2268. up_write(&s->s_umount);
  2269. deactivate_super(s);
  2270. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  2271. return error;
  2272. }
  2273. #endif /* CONFIG_NFS_V4 */