super.c 64 KB

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