super.c 63 KB

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