super.c 65 KB

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