super.c 75 KB

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