super.c 62 KB

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