super.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574
  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. if (errors > 0) {
  1152. dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
  1153. errors, (errors == 1 ? "" : "s"));
  1154. if (!sloppy)
  1155. return 0;
  1156. }
  1157. return 1;
  1158. out_nomem:
  1159. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1160. return 0;
  1161. out_security_failure:
  1162. free_secdata(secdata);
  1163. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1164. return 0;
  1165. }
  1166. /*
  1167. * Use the remote server's MOUNT service to request the NFS file handle
  1168. * corresponding to the provided path.
  1169. */
  1170. static int nfs_try_mount(struct nfs_parsed_mount_data *args,
  1171. struct nfs_fh *root_fh)
  1172. {
  1173. struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
  1174. char *hostname;
  1175. int status;
  1176. if (args->mount_server.version == 0) {
  1177. if (args->flags & NFS_MOUNT_VER3)
  1178. args->mount_server.version = NFS_MNT3_VERSION;
  1179. else
  1180. args->mount_server.version = NFS_MNT_VERSION;
  1181. }
  1182. if (args->mount_server.hostname)
  1183. hostname = args->mount_server.hostname;
  1184. else
  1185. hostname = args->nfs_server.hostname;
  1186. /*
  1187. * Construct the mount server's address.
  1188. */
  1189. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1190. memcpy(sap, &args->nfs_server.address,
  1191. args->nfs_server.addrlen);
  1192. args->mount_server.addrlen = args->nfs_server.addrlen;
  1193. }
  1194. /*
  1195. * autobind will be used if mount_server.port == 0
  1196. */
  1197. nfs_set_port(sap, args->mount_server.port);
  1198. /*
  1199. * Now ask the mount server to map our export path
  1200. * to a file handle.
  1201. */
  1202. status = nfs_mount(sap,
  1203. args->mount_server.addrlen,
  1204. hostname,
  1205. args->nfs_server.export_path,
  1206. args->mount_server.version,
  1207. args->mount_server.protocol,
  1208. root_fh);
  1209. if (status == 0)
  1210. return 0;
  1211. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1212. hostname, status);
  1213. return status;
  1214. }
  1215. static int nfs_parse_simple_hostname(const char *dev_name,
  1216. char **hostname, size_t maxnamlen,
  1217. char **export_path, size_t maxpathlen)
  1218. {
  1219. size_t len;
  1220. char *colon, *comma;
  1221. colon = strchr(dev_name, ':');
  1222. if (colon == NULL)
  1223. goto out_bad_devname;
  1224. len = colon - dev_name;
  1225. if (len > maxnamlen)
  1226. goto out_hostname;
  1227. /* N.B. caller will free nfs_server.hostname in all cases */
  1228. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1229. if (!*hostname)
  1230. goto out_nomem;
  1231. /* kill possible hostname list: not supported */
  1232. comma = strchr(*hostname, ',');
  1233. if (comma != NULL) {
  1234. if (comma == *hostname)
  1235. goto out_bad_devname;
  1236. *comma = '\0';
  1237. }
  1238. colon++;
  1239. len = strlen(colon);
  1240. if (len > maxpathlen)
  1241. goto out_path;
  1242. *export_path = kstrndup(colon, len, GFP_KERNEL);
  1243. if (!*export_path)
  1244. goto out_nomem;
  1245. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1246. return 0;
  1247. out_bad_devname:
  1248. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1249. return -EINVAL;
  1250. out_nomem:
  1251. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1252. return -ENOMEM;
  1253. out_hostname:
  1254. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1255. return -ENAMETOOLONG;
  1256. out_path:
  1257. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1258. return -ENAMETOOLONG;
  1259. }
  1260. /*
  1261. * Hostname has square brackets around it because it contains one or
  1262. * more colons. We look for the first closing square bracket, and a
  1263. * colon must follow it.
  1264. */
  1265. static int nfs_parse_protected_hostname(const char *dev_name,
  1266. char **hostname, size_t maxnamlen,
  1267. char **export_path, size_t maxpathlen)
  1268. {
  1269. size_t len;
  1270. char *start, *end;
  1271. start = (char *)(dev_name + 1);
  1272. end = strchr(start, ']');
  1273. if (end == NULL)
  1274. goto out_bad_devname;
  1275. if (*(end + 1) != ':')
  1276. goto out_bad_devname;
  1277. len = end - start;
  1278. if (len > maxnamlen)
  1279. goto out_hostname;
  1280. /* N.B. caller will free nfs_server.hostname in all cases */
  1281. *hostname = kstrndup(start, len, GFP_KERNEL);
  1282. if (*hostname == NULL)
  1283. goto out_nomem;
  1284. end += 2;
  1285. len = strlen(end);
  1286. if (len > maxpathlen)
  1287. goto out_path;
  1288. *export_path = kstrndup(end, len, GFP_KERNEL);
  1289. if (!*export_path)
  1290. goto out_nomem;
  1291. return 0;
  1292. out_bad_devname:
  1293. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1294. return -EINVAL;
  1295. out_nomem:
  1296. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1297. return -ENOMEM;
  1298. out_hostname:
  1299. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1300. return -ENAMETOOLONG;
  1301. out_path:
  1302. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1303. return -ENAMETOOLONG;
  1304. }
  1305. /*
  1306. * Split "dev_name" into "hostname:export_path".
  1307. *
  1308. * The leftmost colon demarks the split between the server's hostname
  1309. * and the export path. If the hostname starts with a left square
  1310. * bracket, then it may contain colons.
  1311. *
  1312. * Note: caller frees hostname and export path, even on error.
  1313. */
  1314. static int nfs_parse_devname(const char *dev_name,
  1315. char **hostname, size_t maxnamlen,
  1316. char **export_path, size_t maxpathlen)
  1317. {
  1318. if (*dev_name == '[')
  1319. return nfs_parse_protected_hostname(dev_name,
  1320. hostname, maxnamlen,
  1321. export_path, maxpathlen);
  1322. return nfs_parse_simple_hostname(dev_name,
  1323. hostname, maxnamlen,
  1324. export_path, maxpathlen);
  1325. }
  1326. /*
  1327. * Validate the NFS2/NFS3 mount data
  1328. * - fills in the mount root filehandle
  1329. *
  1330. * For option strings, user space handles the following behaviors:
  1331. *
  1332. * + DNS: mapping server host name to IP address ("addr=" option)
  1333. *
  1334. * + failure mode: how to behave if a mount request can't be handled
  1335. * immediately ("fg/bg" option)
  1336. *
  1337. * + retry: how often to retry a mount request ("retry=" option)
  1338. *
  1339. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1340. * mountproto=tcp after mountproto=udp, and so on
  1341. */
  1342. static int nfs_validate_mount_data(void *options,
  1343. struct nfs_parsed_mount_data *args,
  1344. struct nfs_fh *mntfh,
  1345. const char *dev_name)
  1346. {
  1347. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1348. if (data == NULL)
  1349. goto out_no_data;
  1350. args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
  1351. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1352. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1353. args->acregmin = NFS_DEF_ACREGMIN;
  1354. args->acregmax = NFS_DEF_ACREGMAX;
  1355. args->acdirmin = NFS_DEF_ACDIRMIN;
  1356. args->acdirmax = NFS_DEF_ACDIRMAX;
  1357. args->mount_server.port = 0; /* autobind unless user sets port */
  1358. args->nfs_server.port = 0; /* autobind unless user sets port */
  1359. args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1360. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1361. switch (data->version) {
  1362. case 1:
  1363. data->namlen = 0;
  1364. case 2:
  1365. data->bsize = 0;
  1366. case 3:
  1367. if (data->flags & NFS_MOUNT_VER3)
  1368. goto out_no_v3;
  1369. data->root.size = NFS2_FHSIZE;
  1370. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1371. case 4:
  1372. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1373. goto out_no_sec;
  1374. case 5:
  1375. memset(data->context, 0, sizeof(data->context));
  1376. case 6:
  1377. if (data->flags & NFS_MOUNT_VER3) {
  1378. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1379. goto out_invalid_fh;
  1380. mntfh->size = data->root.size;
  1381. } else
  1382. mntfh->size = NFS2_FHSIZE;
  1383. memcpy(mntfh->data, data->root.data, mntfh->size);
  1384. if (mntfh->size < sizeof(mntfh->data))
  1385. memset(mntfh->data + mntfh->size, 0,
  1386. sizeof(mntfh->data) - mntfh->size);
  1387. /*
  1388. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1389. * can deal with.
  1390. */
  1391. args->flags = data->flags;
  1392. args->rsize = data->rsize;
  1393. args->wsize = data->wsize;
  1394. args->timeo = data->timeo;
  1395. args->retrans = data->retrans;
  1396. args->acregmin = data->acregmin;
  1397. args->acregmax = data->acregmax;
  1398. args->acdirmin = data->acdirmin;
  1399. args->acdirmax = data->acdirmax;
  1400. memcpy(&args->nfs_server.address, &data->addr,
  1401. sizeof(data->addr));
  1402. args->nfs_server.addrlen = sizeof(data->addr);
  1403. if (!nfs_verify_server_address((struct sockaddr *)
  1404. &args->nfs_server.address))
  1405. goto out_no_address;
  1406. if (!(data->flags & NFS_MOUNT_TCP))
  1407. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1408. /* N.B. caller will free nfs_server.hostname in all cases */
  1409. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1410. args->namlen = data->namlen;
  1411. args->bsize = data->bsize;
  1412. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1413. args->auth_flavors[0] = data->pseudoflavor;
  1414. if (!args->nfs_server.hostname)
  1415. goto out_nomem;
  1416. /*
  1417. * The legacy version 6 binary mount data from userspace has a
  1418. * field used only to transport selinux information into the
  1419. * the kernel. To continue to support that functionality we
  1420. * have a touch of selinux knowledge here in the NFS code. The
  1421. * userspace code converted context=blah to just blah so we are
  1422. * converting back to the full string selinux understands.
  1423. */
  1424. if (data->context[0]){
  1425. #ifdef CONFIG_SECURITY_SELINUX
  1426. int rc;
  1427. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1428. if (!opts_str)
  1429. return -ENOMEM;
  1430. strcpy(opts_str, "context=");
  1431. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1432. strcat(opts_str, &data->context[0]);
  1433. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1434. kfree(opts_str);
  1435. if (rc)
  1436. return rc;
  1437. #else
  1438. return -EINVAL;
  1439. #endif
  1440. }
  1441. break;
  1442. default: {
  1443. int status;
  1444. if (nfs_parse_mount_options((char *)options, args) == 0)
  1445. return -EINVAL;
  1446. if (!nfs_verify_server_address((struct sockaddr *)
  1447. &args->nfs_server.address))
  1448. goto out_no_address;
  1449. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1450. args->nfs_server.port);
  1451. nfs_set_mount_transport_protocol(args);
  1452. status = nfs_parse_devname(dev_name,
  1453. &args->nfs_server.hostname,
  1454. PAGE_SIZE,
  1455. &args->nfs_server.export_path,
  1456. NFS_MAXPATHLEN);
  1457. if (!status)
  1458. status = nfs_try_mount(args, mntfh);
  1459. kfree(args->nfs_server.export_path);
  1460. args->nfs_server.export_path = NULL;
  1461. if (status)
  1462. return status;
  1463. break;
  1464. }
  1465. }
  1466. #ifndef CONFIG_NFS_V3
  1467. if (args->flags & NFS_MOUNT_VER3)
  1468. goto out_v3_not_compiled;
  1469. #endif /* !CONFIG_NFS_V3 */
  1470. return 0;
  1471. out_no_data:
  1472. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1473. return -EINVAL;
  1474. out_no_v3:
  1475. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1476. data->version);
  1477. return -EINVAL;
  1478. out_no_sec:
  1479. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1480. return -EINVAL;
  1481. #ifndef CONFIG_NFS_V3
  1482. out_v3_not_compiled:
  1483. dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
  1484. return -EPROTONOSUPPORT;
  1485. #endif /* !CONFIG_NFS_V3 */
  1486. out_nomem:
  1487. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1488. return -ENOMEM;
  1489. out_no_address:
  1490. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1491. return -EINVAL;
  1492. out_invalid_fh:
  1493. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1494. return -EINVAL;
  1495. }
  1496. static int
  1497. nfs_compare_remount_data(struct nfs_server *nfss,
  1498. struct nfs_parsed_mount_data *data)
  1499. {
  1500. if (data->flags != nfss->flags ||
  1501. data->rsize != nfss->rsize ||
  1502. data->wsize != nfss->wsize ||
  1503. data->retrans != nfss->client->cl_timeout->to_retries ||
  1504. data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
  1505. data->acregmin != nfss->acregmin / HZ ||
  1506. data->acregmax != nfss->acregmax / HZ ||
  1507. data->acdirmin != nfss->acdirmin / HZ ||
  1508. data->acdirmax != nfss->acdirmax / HZ ||
  1509. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1510. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1511. memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1512. data->nfs_server.addrlen) != 0)
  1513. return -EINVAL;
  1514. return 0;
  1515. }
  1516. static int
  1517. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1518. {
  1519. int error;
  1520. struct nfs_server *nfss = sb->s_fs_info;
  1521. struct nfs_parsed_mount_data *data;
  1522. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1523. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1524. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1525. /*
  1526. * Userspace mount programs that send binary options generally send
  1527. * them populated with default values. We have no way to know which
  1528. * ones were explicitly specified. Fall back to legacy behavior and
  1529. * just return success.
  1530. */
  1531. if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
  1532. (nfsvers <= 3 && (!options || (options->version >= 1 &&
  1533. options->version <= 6))))
  1534. return 0;
  1535. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1536. if (data == NULL)
  1537. return -ENOMEM;
  1538. /* fill out struct with values from existing mount */
  1539. data->flags = nfss->flags;
  1540. data->rsize = nfss->rsize;
  1541. data->wsize = nfss->wsize;
  1542. data->retrans = nfss->client->cl_timeout->to_retries;
  1543. data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
  1544. data->acregmin = nfss->acregmin / HZ;
  1545. data->acregmax = nfss->acregmax / HZ;
  1546. data->acdirmin = nfss->acdirmin / HZ;
  1547. data->acdirmax = nfss->acdirmax / HZ;
  1548. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  1549. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  1550. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  1551. data->nfs_server.addrlen);
  1552. /* overwrite those values with any that were specified */
  1553. error = nfs_parse_mount_options((char *)options, data);
  1554. if (error < 0)
  1555. goto out;
  1556. /* compare new mount options with old ones */
  1557. error = nfs_compare_remount_data(nfss, data);
  1558. out:
  1559. kfree(data);
  1560. return error;
  1561. }
  1562. /*
  1563. * Initialise the common bits of the superblock
  1564. */
  1565. static inline void nfs_initialise_sb(struct super_block *sb)
  1566. {
  1567. struct nfs_server *server = NFS_SB(sb);
  1568. sb->s_magic = NFS_SUPER_MAGIC;
  1569. /* We probably want something more informative here */
  1570. snprintf(sb->s_id, sizeof(sb->s_id),
  1571. "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  1572. if (sb->s_blocksize == 0)
  1573. sb->s_blocksize = nfs_block_bits(server->wsize,
  1574. &sb->s_blocksize_bits);
  1575. if (server->flags & NFS_MOUNT_NOAC)
  1576. sb->s_flags |= MS_SYNCHRONOUS;
  1577. nfs_super_set_maxbytes(sb, server->maxfilesize);
  1578. }
  1579. /*
  1580. * Finish setting up an NFS2/3 superblock
  1581. */
  1582. static void nfs_fill_super(struct super_block *sb,
  1583. struct nfs_parsed_mount_data *data)
  1584. {
  1585. struct nfs_server *server = NFS_SB(sb);
  1586. sb->s_blocksize_bits = 0;
  1587. sb->s_blocksize = 0;
  1588. if (data->bsize)
  1589. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  1590. if (server->flags & NFS_MOUNT_VER3) {
  1591. /* The VFS shouldn't apply the umask to mode bits. We will do
  1592. * so ourselves when necessary.
  1593. */
  1594. sb->s_flags |= MS_POSIXACL;
  1595. sb->s_time_gran = 1;
  1596. }
  1597. sb->s_op = &nfs_sops;
  1598. nfs_initialise_sb(sb);
  1599. }
  1600. /*
  1601. * Finish setting up a cloned NFS2/3 superblock
  1602. */
  1603. static void nfs_clone_super(struct super_block *sb,
  1604. const struct super_block *old_sb)
  1605. {
  1606. struct nfs_server *server = NFS_SB(sb);
  1607. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1608. sb->s_blocksize = old_sb->s_blocksize;
  1609. sb->s_maxbytes = old_sb->s_maxbytes;
  1610. if (server->flags & NFS_MOUNT_VER3) {
  1611. /* The VFS shouldn't apply the umask to mode bits. We will do
  1612. * so ourselves when necessary.
  1613. */
  1614. sb->s_flags |= MS_POSIXACL;
  1615. sb->s_time_gran = 1;
  1616. }
  1617. sb->s_op = old_sb->s_op;
  1618. nfs_initialise_sb(sb);
  1619. }
  1620. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  1621. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  1622. {
  1623. const struct nfs_server *a = s->s_fs_info;
  1624. const struct rpc_clnt *clnt_a = a->client;
  1625. const struct rpc_clnt *clnt_b = b->client;
  1626. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  1627. goto Ebusy;
  1628. if (a->nfs_client != b->nfs_client)
  1629. goto Ebusy;
  1630. if (a->flags != b->flags)
  1631. goto Ebusy;
  1632. if (a->wsize != b->wsize)
  1633. goto Ebusy;
  1634. if (a->rsize != b->rsize)
  1635. goto Ebusy;
  1636. if (a->acregmin != b->acregmin)
  1637. goto Ebusy;
  1638. if (a->acregmax != b->acregmax)
  1639. goto Ebusy;
  1640. if (a->acdirmin != b->acdirmin)
  1641. goto Ebusy;
  1642. if (a->acdirmax != b->acdirmax)
  1643. goto Ebusy;
  1644. if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  1645. goto Ebusy;
  1646. return 1;
  1647. Ebusy:
  1648. return 0;
  1649. }
  1650. struct nfs_sb_mountdata {
  1651. struct nfs_server *server;
  1652. int mntflags;
  1653. };
  1654. static int nfs_set_super(struct super_block *s, void *data)
  1655. {
  1656. struct nfs_sb_mountdata *sb_mntdata = data;
  1657. struct nfs_server *server = sb_mntdata->server;
  1658. int ret;
  1659. s->s_flags = sb_mntdata->mntflags;
  1660. s->s_fs_info = server;
  1661. ret = set_anon_super(s, server);
  1662. if (ret == 0)
  1663. server->s_dev = s->s_dev;
  1664. return ret;
  1665. }
  1666. static int nfs_compare_super_address(struct nfs_server *server1,
  1667. struct nfs_server *server2)
  1668. {
  1669. struct sockaddr *sap1, *sap2;
  1670. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  1671. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  1672. if (sap1->sa_family != sap2->sa_family)
  1673. return 0;
  1674. switch (sap1->sa_family) {
  1675. case AF_INET: {
  1676. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  1677. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  1678. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  1679. return 0;
  1680. if (sin1->sin_port != sin2->sin_port)
  1681. return 0;
  1682. break;
  1683. }
  1684. case AF_INET6: {
  1685. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  1686. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  1687. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  1688. return 0;
  1689. if (sin1->sin6_port != sin2->sin6_port)
  1690. return 0;
  1691. break;
  1692. }
  1693. default:
  1694. return 0;
  1695. }
  1696. return 1;
  1697. }
  1698. static int nfs_compare_super(struct super_block *sb, void *data)
  1699. {
  1700. struct nfs_sb_mountdata *sb_mntdata = data;
  1701. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  1702. int mntflags = sb_mntdata->mntflags;
  1703. if (!nfs_compare_super_address(old, server))
  1704. return 0;
  1705. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  1706. if (old->flags & NFS_MOUNT_UNSHARED)
  1707. return 0;
  1708. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  1709. return 0;
  1710. return nfs_compare_mount_options(sb, server, mntflags);
  1711. }
  1712. static int nfs_bdi_register(struct nfs_server *server)
  1713. {
  1714. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  1715. }
  1716. static int nfs_get_sb(struct file_system_type *fs_type,
  1717. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  1718. {
  1719. struct nfs_server *server = NULL;
  1720. struct super_block *s;
  1721. struct nfs_parsed_mount_data *data;
  1722. struct nfs_fh *mntfh;
  1723. struct dentry *mntroot;
  1724. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1725. struct nfs_sb_mountdata sb_mntdata = {
  1726. .mntflags = flags,
  1727. };
  1728. int error = -ENOMEM;
  1729. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1730. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  1731. if (data == NULL || mntfh == NULL)
  1732. goto out_free_fh;
  1733. security_init_mnt_opts(&data->lsm_opts);
  1734. /* Validate the mount data */
  1735. error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
  1736. if (error < 0)
  1737. goto out;
  1738. /* Get a volume representation */
  1739. server = nfs_create_server(data, mntfh);
  1740. if (IS_ERR(server)) {
  1741. error = PTR_ERR(server);
  1742. goto out;
  1743. }
  1744. sb_mntdata.server = server;
  1745. if (server->flags & NFS_MOUNT_UNSHARED)
  1746. compare_super = NULL;
  1747. /* Get a superblock - note that we may end up sharing one that already exists */
  1748. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1749. if (IS_ERR(s)) {
  1750. error = PTR_ERR(s);
  1751. goto out_err_nosb;
  1752. }
  1753. if (s->s_fs_info != server) {
  1754. nfs_free_server(server);
  1755. server = NULL;
  1756. } else {
  1757. error = nfs_bdi_register(server);
  1758. if (error)
  1759. goto error_splat_super;
  1760. }
  1761. if (!s->s_root) {
  1762. /* initial superblock/root creation */
  1763. nfs_fill_super(s, data);
  1764. }
  1765. mntroot = nfs_get_root(s, mntfh);
  1766. if (IS_ERR(mntroot)) {
  1767. error = PTR_ERR(mntroot);
  1768. goto error_splat_super;
  1769. }
  1770. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  1771. if (error)
  1772. goto error_splat_root;
  1773. s->s_flags |= MS_ACTIVE;
  1774. mnt->mnt_sb = s;
  1775. mnt->mnt_root = mntroot;
  1776. error = 0;
  1777. out:
  1778. kfree(data->nfs_server.hostname);
  1779. kfree(data->mount_server.hostname);
  1780. security_free_mnt_opts(&data->lsm_opts);
  1781. out_free_fh:
  1782. kfree(mntfh);
  1783. kfree(data);
  1784. return error;
  1785. out_err_nosb:
  1786. nfs_free_server(server);
  1787. goto out;
  1788. error_splat_root:
  1789. dput(mntroot);
  1790. error_splat_super:
  1791. up_write(&s->s_umount);
  1792. deactivate_super(s);
  1793. goto out;
  1794. }
  1795. /*
  1796. * Destroy an NFS2/3 superblock
  1797. */
  1798. static void nfs_kill_super(struct super_block *s)
  1799. {
  1800. struct nfs_server *server = NFS_SB(s);
  1801. bdi_unregister(&server->backing_dev_info);
  1802. kill_anon_super(s);
  1803. nfs_free_server(server);
  1804. }
  1805. /*
  1806. * Clone an NFS2/3 server record on xdev traversal (FSID-change)
  1807. */
  1808. static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
  1809. const char *dev_name, void *raw_data,
  1810. struct vfsmount *mnt)
  1811. {
  1812. struct nfs_clone_mount *data = raw_data;
  1813. struct super_block *s;
  1814. struct nfs_server *server;
  1815. struct dentry *mntroot;
  1816. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  1817. struct nfs_sb_mountdata sb_mntdata = {
  1818. .mntflags = flags,
  1819. };
  1820. int error;
  1821. dprintk("--> nfs_xdev_get_sb()\n");
  1822. /* create a new volume representation */
  1823. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  1824. if (IS_ERR(server)) {
  1825. error = PTR_ERR(server);
  1826. goto out_err_noserver;
  1827. }
  1828. sb_mntdata.server = server;
  1829. if (server->flags & NFS_MOUNT_UNSHARED)
  1830. compare_super = NULL;
  1831. /* Get a superblock - note that we may end up sharing one that already exists */
  1832. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  1833. if (IS_ERR(s)) {
  1834. error = PTR_ERR(s);
  1835. goto out_err_nosb;
  1836. }
  1837. if (s->s_fs_info != server) {
  1838. nfs_free_server(server);
  1839. server = NULL;
  1840. } else {
  1841. error = nfs_bdi_register(server);
  1842. if (error)
  1843. goto error_splat_super;
  1844. }
  1845. if (!s->s_root) {
  1846. /* initial superblock/root creation */
  1847. nfs_clone_super(s, data->sb);
  1848. }
  1849. mntroot = nfs_get_root(s, data->fh);
  1850. if (IS_ERR(mntroot)) {
  1851. error = PTR_ERR(mntroot);
  1852. goto error_splat_super;
  1853. }
  1854. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  1855. dput(mntroot);
  1856. error = -ESTALE;
  1857. goto error_splat_super;
  1858. }
  1859. s->s_flags |= MS_ACTIVE;
  1860. mnt->mnt_sb = s;
  1861. mnt->mnt_root = mntroot;
  1862. /* clone any lsm security options from the parent to the new sb */
  1863. security_sb_clone_mnt_opts(data->sb, s);
  1864. dprintk("<-- nfs_xdev_get_sb() = 0\n");
  1865. return 0;
  1866. out_err_nosb:
  1867. nfs_free_server(server);
  1868. out_err_noserver:
  1869. dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
  1870. return error;
  1871. error_splat_super:
  1872. up_write(&s->s_umount);
  1873. deactivate_super(s);
  1874. dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
  1875. return error;
  1876. }
  1877. #ifdef CONFIG_NFS_V4
  1878. /*
  1879. * Finish setting up a cloned NFS4 superblock
  1880. */
  1881. static void nfs4_clone_super(struct super_block *sb,
  1882. const struct super_block *old_sb)
  1883. {
  1884. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  1885. sb->s_blocksize = old_sb->s_blocksize;
  1886. sb->s_maxbytes = old_sb->s_maxbytes;
  1887. sb->s_time_gran = 1;
  1888. sb->s_op = old_sb->s_op;
  1889. nfs_initialise_sb(sb);
  1890. }
  1891. /*
  1892. * Set up an NFS4 superblock
  1893. */
  1894. static void nfs4_fill_super(struct super_block *sb)
  1895. {
  1896. sb->s_time_gran = 1;
  1897. sb->s_op = &nfs4_sops;
  1898. nfs_initialise_sb(sb);
  1899. }
  1900. /*
  1901. * Validate NFSv4 mount options
  1902. */
  1903. static int nfs4_validate_mount_data(void *options,
  1904. struct nfs_parsed_mount_data *args,
  1905. const char *dev_name)
  1906. {
  1907. struct sockaddr_in *ap;
  1908. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  1909. char *c;
  1910. if (data == NULL)
  1911. goto out_no_data;
  1912. args->rsize = NFS_MAX_FILE_IO_SIZE;
  1913. args->wsize = NFS_MAX_FILE_IO_SIZE;
  1914. args->acregmin = NFS_DEF_ACREGMIN;
  1915. args->acregmax = NFS_DEF_ACREGMAX;
  1916. args->acdirmin = NFS_DEF_ACDIRMIN;
  1917. args->acdirmax = NFS_DEF_ACDIRMAX;
  1918. args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
  1919. args->auth_flavors[0] = RPC_AUTH_UNIX;
  1920. args->auth_flavor_len = 0;
  1921. switch (data->version) {
  1922. case 1:
  1923. ap = (struct sockaddr_in *)&args->nfs_server.address;
  1924. if (data->host_addrlen > sizeof(args->nfs_server.address))
  1925. goto out_no_address;
  1926. if (data->host_addrlen == 0)
  1927. goto out_no_address;
  1928. args->nfs_server.addrlen = data->host_addrlen;
  1929. if (copy_from_user(ap, data->host_addr, data->host_addrlen))
  1930. return -EFAULT;
  1931. if (!nfs_verify_server_address((struct sockaddr *)
  1932. &args->nfs_server.address))
  1933. goto out_no_address;
  1934. if (data->auth_flavourlen) {
  1935. if (data->auth_flavourlen > 1)
  1936. goto out_inval_auth;
  1937. if (copy_from_user(&args->auth_flavors[0],
  1938. data->auth_flavours,
  1939. sizeof(args->auth_flavors[0])))
  1940. return -EFAULT;
  1941. }
  1942. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  1943. if (IS_ERR(c))
  1944. return PTR_ERR(c);
  1945. args->nfs_server.hostname = c;
  1946. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  1947. if (IS_ERR(c))
  1948. return PTR_ERR(c);
  1949. args->nfs_server.export_path = c;
  1950. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  1951. c = strndup_user(data->client_addr.data, 16);
  1952. if (IS_ERR(c))
  1953. return PTR_ERR(c);
  1954. args->client_address = c;
  1955. /*
  1956. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  1957. * can deal with.
  1958. */
  1959. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  1960. args->rsize = data->rsize;
  1961. args->wsize = data->wsize;
  1962. args->timeo = data->timeo;
  1963. args->retrans = data->retrans;
  1964. args->acregmin = data->acregmin;
  1965. args->acregmax = data->acregmax;
  1966. args->acdirmin = data->acdirmin;
  1967. args->acdirmax = data->acdirmax;
  1968. args->nfs_server.protocol = data->proto;
  1969. nfs_validate_transport_protocol(args);
  1970. break;
  1971. default: {
  1972. int status;
  1973. if (nfs_parse_mount_options((char *)options, args) == 0)
  1974. return -EINVAL;
  1975. if (!nfs_verify_server_address((struct sockaddr *)
  1976. &args->nfs_server.address))
  1977. return -EINVAL;
  1978. nfs_set_port((struct sockaddr *)&args->nfs_server.address,
  1979. args->nfs_server.port);
  1980. nfs_validate_transport_protocol(args);
  1981. if (args->auth_flavor_len > 1)
  1982. goto out_inval_auth;
  1983. if (args->client_address == NULL)
  1984. goto out_no_client_address;
  1985. status = nfs_parse_devname(dev_name,
  1986. &args->nfs_server.hostname,
  1987. NFS4_MAXNAMLEN,
  1988. &args->nfs_server.export_path,
  1989. NFS4_MAXPATHLEN);
  1990. if (status < 0)
  1991. return status;
  1992. break;
  1993. }
  1994. }
  1995. return 0;
  1996. out_no_data:
  1997. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  1998. return -EINVAL;
  1999. out_inval_auth:
  2000. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  2001. data->auth_flavourlen);
  2002. return -EINVAL;
  2003. out_no_address:
  2004. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  2005. return -EINVAL;
  2006. out_no_client_address:
  2007. dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
  2008. return -EINVAL;
  2009. }
  2010. /*
  2011. * Get the superblock for an NFS4 mountpoint
  2012. */
  2013. static int nfs4_get_sb(struct file_system_type *fs_type,
  2014. int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
  2015. {
  2016. struct nfs_parsed_mount_data *data;
  2017. struct super_block *s;
  2018. struct nfs_server *server;
  2019. struct nfs_fh *mntfh;
  2020. struct dentry *mntroot;
  2021. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2022. struct nfs_sb_mountdata sb_mntdata = {
  2023. .mntflags = flags,
  2024. };
  2025. int error = -ENOMEM;
  2026. data = kzalloc(sizeof(*data), GFP_KERNEL);
  2027. mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
  2028. if (data == NULL || mntfh == NULL)
  2029. goto out_free_fh;
  2030. security_init_mnt_opts(&data->lsm_opts);
  2031. /* Validate the mount data */
  2032. error = nfs4_validate_mount_data(raw_data, data, dev_name);
  2033. if (error < 0)
  2034. goto out;
  2035. /* Get a volume representation */
  2036. server = nfs4_create_server(data, mntfh);
  2037. if (IS_ERR(server)) {
  2038. error = PTR_ERR(server);
  2039. goto out;
  2040. }
  2041. sb_mntdata.server = server;
  2042. if (server->flags & NFS4_MOUNT_UNSHARED)
  2043. compare_super = NULL;
  2044. /* Get a superblock - note that we may end up sharing one that already exists */
  2045. s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2046. if (IS_ERR(s)) {
  2047. error = PTR_ERR(s);
  2048. goto out_free;
  2049. }
  2050. if (s->s_fs_info != server) {
  2051. nfs_free_server(server);
  2052. server = NULL;
  2053. } else {
  2054. error = nfs_bdi_register(server);
  2055. if (error)
  2056. goto error_splat_super;
  2057. }
  2058. if (!s->s_root) {
  2059. /* initial superblock/root creation */
  2060. nfs4_fill_super(s);
  2061. }
  2062. mntroot = nfs4_get_root(s, mntfh);
  2063. if (IS_ERR(mntroot)) {
  2064. error = PTR_ERR(mntroot);
  2065. goto error_splat_super;
  2066. }
  2067. error = security_sb_set_mnt_opts(s, &data->lsm_opts);
  2068. if (error)
  2069. goto error_splat_root;
  2070. s->s_flags |= MS_ACTIVE;
  2071. mnt->mnt_sb = s;
  2072. mnt->mnt_root = mntroot;
  2073. error = 0;
  2074. out:
  2075. kfree(data->client_address);
  2076. kfree(data->nfs_server.export_path);
  2077. kfree(data->nfs_server.hostname);
  2078. security_free_mnt_opts(&data->lsm_opts);
  2079. out_free_fh:
  2080. kfree(mntfh);
  2081. kfree(data);
  2082. return error;
  2083. out_free:
  2084. nfs_free_server(server);
  2085. goto out;
  2086. error_splat_root:
  2087. dput(mntroot);
  2088. error_splat_super:
  2089. up_write(&s->s_umount);
  2090. deactivate_super(s);
  2091. goto out;
  2092. }
  2093. static void nfs4_kill_super(struct super_block *sb)
  2094. {
  2095. struct nfs_server *server = NFS_SB(sb);
  2096. nfs_return_all_delegations(sb);
  2097. kill_anon_super(sb);
  2098. nfs4_renewd_prepare_shutdown(server);
  2099. nfs_free_server(server);
  2100. }
  2101. /*
  2102. * Clone an NFS4 server record on xdev traversal (FSID-change)
  2103. */
  2104. static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
  2105. const char *dev_name, void *raw_data,
  2106. struct vfsmount *mnt)
  2107. {
  2108. struct nfs_clone_mount *data = raw_data;
  2109. struct super_block *s;
  2110. struct nfs_server *server;
  2111. struct dentry *mntroot;
  2112. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2113. struct nfs_sb_mountdata sb_mntdata = {
  2114. .mntflags = flags,
  2115. };
  2116. int error;
  2117. dprintk("--> nfs4_xdev_get_sb()\n");
  2118. /* create a new volume representation */
  2119. server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
  2120. if (IS_ERR(server)) {
  2121. error = PTR_ERR(server);
  2122. goto out_err_noserver;
  2123. }
  2124. sb_mntdata.server = server;
  2125. if (server->flags & NFS4_MOUNT_UNSHARED)
  2126. compare_super = NULL;
  2127. /* Get a superblock - note that we may end up sharing one that already exists */
  2128. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2129. if (IS_ERR(s)) {
  2130. error = PTR_ERR(s);
  2131. goto out_err_nosb;
  2132. }
  2133. if (s->s_fs_info != server) {
  2134. nfs_free_server(server);
  2135. server = NULL;
  2136. } else {
  2137. error = nfs_bdi_register(server);
  2138. if (error)
  2139. goto error_splat_super;
  2140. }
  2141. if (!s->s_root) {
  2142. /* initial superblock/root creation */
  2143. nfs4_clone_super(s, data->sb);
  2144. }
  2145. mntroot = nfs4_get_root(s, data->fh);
  2146. if (IS_ERR(mntroot)) {
  2147. error = PTR_ERR(mntroot);
  2148. goto error_splat_super;
  2149. }
  2150. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2151. dput(mntroot);
  2152. error = -ESTALE;
  2153. goto error_splat_super;
  2154. }
  2155. s->s_flags |= MS_ACTIVE;
  2156. mnt->mnt_sb = s;
  2157. mnt->mnt_root = mntroot;
  2158. security_sb_clone_mnt_opts(data->sb, s);
  2159. dprintk("<-- nfs4_xdev_get_sb() = 0\n");
  2160. return 0;
  2161. out_err_nosb:
  2162. nfs_free_server(server);
  2163. out_err_noserver:
  2164. dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
  2165. return error;
  2166. error_splat_super:
  2167. up_write(&s->s_umount);
  2168. deactivate_super(s);
  2169. dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
  2170. return error;
  2171. }
  2172. /*
  2173. * Create an NFS4 server record on referral traversal
  2174. */
  2175. static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
  2176. const char *dev_name, void *raw_data,
  2177. struct vfsmount *mnt)
  2178. {
  2179. struct nfs_clone_mount *data = raw_data;
  2180. struct super_block *s;
  2181. struct nfs_server *server;
  2182. struct dentry *mntroot;
  2183. struct nfs_fh mntfh;
  2184. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2185. struct nfs_sb_mountdata sb_mntdata = {
  2186. .mntflags = flags,
  2187. };
  2188. int error;
  2189. dprintk("--> nfs4_referral_get_sb()\n");
  2190. /* create a new volume representation */
  2191. server = nfs4_create_referral_server(data, &mntfh);
  2192. if (IS_ERR(server)) {
  2193. error = PTR_ERR(server);
  2194. goto out_err_noserver;
  2195. }
  2196. sb_mntdata.server = server;
  2197. if (server->flags & NFS4_MOUNT_UNSHARED)
  2198. compare_super = NULL;
  2199. /* Get a superblock - note that we may end up sharing one that already exists */
  2200. s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
  2201. if (IS_ERR(s)) {
  2202. error = PTR_ERR(s);
  2203. goto out_err_nosb;
  2204. }
  2205. if (s->s_fs_info != server) {
  2206. nfs_free_server(server);
  2207. server = NULL;
  2208. } else {
  2209. error = nfs_bdi_register(server);
  2210. if (error)
  2211. goto error_splat_super;
  2212. }
  2213. if (!s->s_root) {
  2214. /* initial superblock/root creation */
  2215. nfs4_fill_super(s);
  2216. }
  2217. mntroot = nfs4_get_root(s, &mntfh);
  2218. if (IS_ERR(mntroot)) {
  2219. error = PTR_ERR(mntroot);
  2220. goto error_splat_super;
  2221. }
  2222. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
  2223. dput(mntroot);
  2224. error = -ESTALE;
  2225. goto error_splat_super;
  2226. }
  2227. s->s_flags |= MS_ACTIVE;
  2228. mnt->mnt_sb = s;
  2229. mnt->mnt_root = mntroot;
  2230. security_sb_clone_mnt_opts(data->sb, s);
  2231. dprintk("<-- nfs4_referral_get_sb() = 0\n");
  2232. return 0;
  2233. out_err_nosb:
  2234. nfs_free_server(server);
  2235. out_err_noserver:
  2236. dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
  2237. return error;
  2238. error_splat_super:
  2239. up_write(&s->s_umount);
  2240. deactivate_super(s);
  2241. dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
  2242. return error;
  2243. }
  2244. #endif /* CONFIG_NFS_V4 */