super.c 76 KB

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