super.c 74 KB

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