super.c 66 KB

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