super.c 67 KB

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