super.c 74 KB

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