]>
Commit | Line | Data |
---|---|---|
9954bf92 DH |
1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* | |
3 | * linux/fs/nfs/fs_context.c | |
4 | * | |
5 | * Copyright (C) 1992 Rick Sladkey | |
f2aedb71 | 6 | * Conversion to new mount api Copyright (C) David Howells |
9954bf92 DH |
7 | * |
8 | * NFS mount handling. | |
9 | * | |
10 | * Split from fs/nfs/super.c by David Howells <dhowells@redhat.com> | |
11 | */ | |
12 | ||
13 | #include <linux/module.h> | |
14 | #include <linux/fs.h> | |
e38bb238 SM |
15 | #include <linux/fs_context.h> |
16 | #include <linux/fs_parser.h> | |
9954bf92 DH |
17 | #include <linux/nfs_fs.h> |
18 | #include <linux/nfs_mount.h> | |
19 | #include <linux/nfs4_mount.h> | |
20 | #include "nfs.h" | |
21 | #include "internal.h" | |
22 | ||
23 | #define NFSDBG_FACILITY NFSDBG_MOUNT | |
24 | ||
25 | #if IS_ENABLED(CONFIG_NFS_V3) | |
26 | #define NFS_DEFAULT_VERSION 3 | |
27 | #else | |
28 | #define NFS_DEFAULT_VERSION 2 | |
29 | #endif | |
30 | ||
31 | #define NFS_MAX_CONNECTIONS 16 | |
32 | ||
e38bb238 SM |
33 | enum nfs_param { |
34 | Opt_ac, | |
35 | Opt_acdirmax, | |
36 | Opt_acdirmin, | |
37 | Opt_acl, | |
38 | Opt_acregmax, | |
39 | Opt_acregmin, | |
9954bf92 | 40 | Opt_actimeo, |
e38bb238 SM |
41 | Opt_addr, |
42 | Opt_bg, | |
43 | Opt_bsize, | |
44 | Opt_clientaddr, | |
45 | Opt_cto, | |
46 | Opt_fg, | |
47 | Opt_fscache, | |
48ce73b1 | 48 | Opt_fscache_flag, |
e38bb238 SM |
49 | Opt_hard, |
50 | Opt_intr, | |
51 | Opt_local_lock, | |
52 | Opt_lock, | |
53 | Opt_lookupcache, | |
54 | Opt_migration, | |
55 | Opt_minorversion, | |
56 | Opt_mountaddr, | |
57 | Opt_mounthost, | |
9954bf92 | 58 | Opt_mountport, |
e38bb238 | 59 | Opt_mountproto, |
9954bf92 | 60 | Opt_mountvers, |
e38bb238 | 61 | Opt_namelen, |
9954bf92 | 62 | Opt_nconnect, |
e38bb238 SM |
63 | Opt_port, |
64 | Opt_posix, | |
65 | Opt_proto, | |
66 | Opt_rdirplus, | |
67 | Opt_rdma, | |
68 | Opt_resvport, | |
69 | Opt_retrans, | |
70 | Opt_retry, | |
71 | Opt_rsize, | |
72 | Opt_sec, | |
73 | Opt_sharecache, | |
74 | Opt_sloppy, | |
75 | Opt_soft, | |
76 | Opt_softerr, | |
c74dfe97 | 77 | Opt_softreval, |
e38bb238 SM |
78 | Opt_source, |
79 | Opt_tcp, | |
80 | Opt_timeo, | |
81 | Opt_udp, | |
82 | Opt_v, | |
83 | Opt_vers, | |
84 | Opt_wsize, | |
9954bf92 DH |
85 | }; |
86 | ||
2710c957 AV |
87 | enum { |
88 | Opt_local_lock_all, | |
89 | Opt_local_lock_flock, | |
90 | Opt_local_lock_none, | |
91 | Opt_local_lock_posix, | |
92 | }; | |
93 | ||
5eede625 | 94 | static const struct constant_table nfs_param_enums_local_lock[] = { |
2710c957 AV |
95 | { "all", Opt_local_lock_all }, |
96 | { "flock", Opt_local_lock_flock }, | |
97 | { "none", Opt_local_lock_none }, | |
98 | {} | |
99 | }; | |
100 | ||
101 | enum { | |
102 | Opt_lookupcache_all, | |
103 | Opt_lookupcache_none, | |
104 | Opt_lookupcache_positive, | |
105 | }; | |
106 | ||
5eede625 | 107 | static const struct constant_table nfs_param_enums_lookupcache[] = { |
2710c957 AV |
108 | { "all", Opt_lookupcache_all }, |
109 | { "none", Opt_lookupcache_none }, | |
110 | { "pos", Opt_lookupcache_positive }, | |
111 | { "positive", Opt_lookupcache_positive }, | |
112 | {} | |
113 | }; | |
114 | ||
d7167b14 | 115 | static const struct fs_parameter_spec nfs_fs_parameters[] = { |
e38bb238 SM |
116 | fsparam_flag_no("ac", Opt_ac), |
117 | fsparam_u32 ("acdirmax", Opt_acdirmax), | |
118 | fsparam_u32 ("acdirmin", Opt_acdirmin), | |
119 | fsparam_flag_no("acl", Opt_acl), | |
120 | fsparam_u32 ("acregmax", Opt_acregmax), | |
121 | fsparam_u32 ("acregmin", Opt_acregmin), | |
122 | fsparam_u32 ("actimeo", Opt_actimeo), | |
123 | fsparam_string("addr", Opt_addr), | |
124 | fsparam_flag ("bg", Opt_bg), | |
125 | fsparam_u32 ("bsize", Opt_bsize), | |
126 | fsparam_string("clientaddr", Opt_clientaddr), | |
127 | fsparam_flag_no("cto", Opt_cto), | |
128 | fsparam_flag ("fg", Opt_fg), | |
48ce73b1 AV |
129 | fsparam_flag_no("fsc", Opt_fscache_flag), |
130 | fsparam_string("fsc", Opt_fscache), | |
e38bb238 | 131 | fsparam_flag ("hard", Opt_hard), |
328de528 | 132 | __fsparam(NULL, "intr", Opt_intr, |
2710c957 AV |
133 | fs_param_neg_with_no|fs_param_deprecated, NULL), |
134 | fsparam_enum ("local_lock", Opt_local_lock, nfs_param_enums_local_lock), | |
e38bb238 | 135 | fsparam_flag_no("lock", Opt_lock), |
2710c957 | 136 | fsparam_enum ("lookupcache", Opt_lookupcache, nfs_param_enums_lookupcache), |
e38bb238 SM |
137 | fsparam_flag_no("migration", Opt_migration), |
138 | fsparam_u32 ("minorversion", Opt_minorversion), | |
139 | fsparam_string("mountaddr", Opt_mountaddr), | |
140 | fsparam_string("mounthost", Opt_mounthost), | |
141 | fsparam_u32 ("mountport", Opt_mountport), | |
142 | fsparam_string("mountproto", Opt_mountproto), | |
143 | fsparam_u32 ("mountvers", Opt_mountvers), | |
144 | fsparam_u32 ("namlen", Opt_namelen), | |
145 | fsparam_u32 ("nconnect", Opt_nconnect), | |
146 | fsparam_string("nfsvers", Opt_vers), | |
147 | fsparam_u32 ("port", Opt_port), | |
148 | fsparam_flag_no("posix", Opt_posix), | |
149 | fsparam_string("proto", Opt_proto), | |
150 | fsparam_flag_no("rdirplus", Opt_rdirplus), | |
151 | fsparam_flag ("rdma", Opt_rdma), | |
152 | fsparam_flag_no("resvport", Opt_resvport), | |
153 | fsparam_u32 ("retrans", Opt_retrans), | |
154 | fsparam_string("retry", Opt_retry), | |
155 | fsparam_u32 ("rsize", Opt_rsize), | |
156 | fsparam_string("sec", Opt_sec), | |
157 | fsparam_flag_no("sharecache", Opt_sharecache), | |
158 | fsparam_flag ("sloppy", Opt_sloppy), | |
159 | fsparam_flag ("soft", Opt_soft), | |
160 | fsparam_flag ("softerr", Opt_softerr), | |
c74dfe97 | 161 | fsparam_flag ("softreval", Opt_softreval), |
e38bb238 SM |
162 | fsparam_string("source", Opt_source), |
163 | fsparam_flag ("tcp", Opt_tcp), | |
164 | fsparam_u32 ("timeo", Opt_timeo), | |
165 | fsparam_flag ("udp", Opt_udp), | |
166 | fsparam_flag ("v2", Opt_v), | |
167 | fsparam_flag ("v3", Opt_v), | |
168 | fsparam_flag ("v4", Opt_v), | |
169 | fsparam_flag ("v4.0", Opt_v), | |
170 | fsparam_flag ("v4.1", Opt_v), | |
171 | fsparam_flag ("v4.2", Opt_v), | |
172 | fsparam_string("vers", Opt_vers), | |
173 | fsparam_u32 ("wsize", Opt_wsize), | |
174 | {} | |
9954bf92 DH |
175 | }; |
176 | ||
9954bf92 | 177 | enum { |
e38bb238 SM |
178 | Opt_vers_2, |
179 | Opt_vers_3, | |
180 | Opt_vers_4, | |
181 | Opt_vers_4_0, | |
182 | Opt_vers_4_1, | |
183 | Opt_vers_4_2, | |
9954bf92 DH |
184 | }; |
185 | ||
e38bb238 SM |
186 | static const struct constant_table nfs_vers_tokens[] = { |
187 | { "2", Opt_vers_2 }, | |
188 | { "3", Opt_vers_3 }, | |
189 | { "4", Opt_vers_4 }, | |
190 | { "4.0", Opt_vers_4_0 }, | |
191 | { "4.1", Opt_vers_4_1 }, | |
192 | { "4.2", Opt_vers_4_2 }, | |
9954bf92 DH |
193 | }; |
194 | ||
195 | enum { | |
e38bb238 SM |
196 | Opt_xprt_rdma, |
197 | Opt_xprt_rdma6, | |
198 | Opt_xprt_tcp, | |
199 | Opt_xprt_tcp6, | |
200 | Opt_xprt_udp, | |
201 | Opt_xprt_udp6, | |
202 | nr__Opt_xprt | |
9954bf92 DH |
203 | }; |
204 | ||
e38bb238 SM |
205 | static const struct constant_table nfs_xprt_protocol_tokens[nr__Opt_xprt] = { |
206 | { "rdma", Opt_xprt_rdma }, | |
207 | { "rdma6", Opt_xprt_rdma6 }, | |
208 | { "tcp", Opt_xprt_tcp }, | |
209 | { "tcp6", Opt_xprt_tcp6 }, | |
210 | { "udp", Opt_xprt_udp }, | |
211 | { "udp6", Opt_xprt_udp6 }, | |
9954bf92 DH |
212 | }; |
213 | ||
214 | enum { | |
e38bb238 SM |
215 | Opt_sec_krb5, |
216 | Opt_sec_krb5i, | |
217 | Opt_sec_krb5p, | |
218 | Opt_sec_lkey, | |
219 | Opt_sec_lkeyi, | |
220 | Opt_sec_lkeyp, | |
221 | Opt_sec_none, | |
222 | Opt_sec_spkm, | |
223 | Opt_sec_spkmi, | |
224 | Opt_sec_spkmp, | |
225 | Opt_sec_sys, | |
226 | nr__Opt_sec | |
9954bf92 DH |
227 | }; |
228 | ||
e38bb238 SM |
229 | static const struct constant_table nfs_secflavor_tokens[] = { |
230 | { "krb5", Opt_sec_krb5 }, | |
231 | { "krb5i", Opt_sec_krb5i }, | |
232 | { "krb5p", Opt_sec_krb5p }, | |
233 | { "lkey", Opt_sec_lkey }, | |
234 | { "lkeyi", Opt_sec_lkeyi }, | |
235 | { "lkeyp", Opt_sec_lkeyp }, | |
236 | { "none", Opt_sec_none }, | |
237 | { "null", Opt_sec_none }, | |
238 | { "spkm3", Opt_sec_spkm }, | |
239 | { "spkm3i", Opt_sec_spkmi }, | |
240 | { "spkm3p", Opt_sec_spkmp }, | |
241 | { "sys", Opt_sec_sys }, | |
9954bf92 DH |
242 | }; |
243 | ||
9954bf92 DH |
244 | /* |
245 | * Sanity-check a server address provided by the mount command. | |
246 | * | |
247 | * Address family must be initialized, and address must not be | |
248 | * the ANY address for that family. | |
249 | */ | |
250 | static int nfs_verify_server_address(struct sockaddr *addr) | |
251 | { | |
252 | switch (addr->sa_family) { | |
253 | case AF_INET: { | |
254 | struct sockaddr_in *sa = (struct sockaddr_in *)addr; | |
255 | return sa->sin_addr.s_addr != htonl(INADDR_ANY); | |
256 | } | |
257 | case AF_INET6: { | |
258 | struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; | |
259 | return !ipv6_addr_any(sa); | |
260 | } | |
261 | } | |
262 | ||
263 | dfprintk(MOUNT, "NFS: Invalid IP address specified\n"); | |
264 | return 0; | |
265 | } | |
266 | ||
267 | /* | |
268 | * Sanity check the NFS transport protocol. | |
269 | * | |
270 | */ | |
5eb005ca | 271 | static void nfs_validate_transport_protocol(struct nfs_fs_context *ctx) |
9954bf92 | 272 | { |
5eb005ca | 273 | switch (ctx->nfs_server.protocol) { |
9954bf92 DH |
274 | case XPRT_TRANSPORT_UDP: |
275 | case XPRT_TRANSPORT_TCP: | |
276 | case XPRT_TRANSPORT_RDMA: | |
277 | break; | |
278 | default: | |
5eb005ca | 279 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
9954bf92 DH |
280 | } |
281 | } | |
282 | ||
283 | /* | |
284 | * For text based NFSv2/v3 mounts, the mount protocol transport default | |
285 | * settings should depend upon the specified NFS transport. | |
286 | */ | |
5eb005ca | 287 | static void nfs_set_mount_transport_protocol(struct nfs_fs_context *ctx) |
9954bf92 | 288 | { |
5eb005ca | 289 | nfs_validate_transport_protocol(ctx); |
9954bf92 | 290 | |
5eb005ca DH |
291 | if (ctx->mount_server.protocol == XPRT_TRANSPORT_UDP || |
292 | ctx->mount_server.protocol == XPRT_TRANSPORT_TCP) | |
9954bf92 | 293 | return; |
5eb005ca | 294 | switch (ctx->nfs_server.protocol) { |
9954bf92 | 295 | case XPRT_TRANSPORT_UDP: |
5eb005ca | 296 | ctx->mount_server.protocol = XPRT_TRANSPORT_UDP; |
9954bf92 DH |
297 | break; |
298 | case XPRT_TRANSPORT_TCP: | |
299 | case XPRT_TRANSPORT_RDMA: | |
5eb005ca | 300 | ctx->mount_server.protocol = XPRT_TRANSPORT_TCP; |
9954bf92 DH |
301 | } |
302 | } | |
303 | ||
304 | /* | |
305 | * Add 'flavor' to 'auth_info' if not already present. | |
306 | * Returns true if 'flavor' ends up in the list, false otherwise | |
307 | */ | |
62a55d08 | 308 | static int nfs_auth_info_add(struct fs_context *fc, |
e558100f DH |
309 | struct nfs_auth_info *auth_info, |
310 | rpc_authflavor_t flavor) | |
9954bf92 DH |
311 | { |
312 | unsigned int i; | |
313 | unsigned int max_flavor_len = ARRAY_SIZE(auth_info->flavors); | |
314 | ||
315 | /* make sure this flavor isn't already in the list */ | |
316 | for (i = 0; i < auth_info->flavor_len; i++) { | |
317 | if (flavor == auth_info->flavors[i]) | |
e558100f | 318 | return 0; |
9954bf92 DH |
319 | } |
320 | ||
ce8866f0 SM |
321 | if (auth_info->flavor_len + 1 >= max_flavor_len) |
322 | return nfs_invalf(fc, "NFS: too many sec= flavors"); | |
9954bf92 DH |
323 | |
324 | auth_info->flavors[auth_info->flavor_len++] = flavor; | |
e558100f | 325 | return 0; |
9954bf92 DH |
326 | } |
327 | ||
328 | /* | |
329 | * Parse the value of the 'sec=' option. | |
330 | */ | |
62a55d08 | 331 | static int nfs_parse_security_flavors(struct fs_context *fc, |
e38bb238 | 332 | struct fs_parameter *param) |
9954bf92 | 333 | { |
62a55d08 | 334 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
9954bf92 | 335 | rpc_authflavor_t pseudoflavor; |
e38bb238 | 336 | char *string = param->string, *p; |
e558100f | 337 | int ret; |
9954bf92 | 338 | |
e38bb238 | 339 | dfprintk(MOUNT, "NFS: parsing %s=%s option\n", param->key, param->string); |
9954bf92 | 340 | |
e38bb238 SM |
341 | while ((p = strsep(&string, ":")) != NULL) { |
342 | if (!*p) | |
343 | continue; | |
344 | switch (lookup_constant(nfs_secflavor_tokens, p, -1)) { | |
9954bf92 DH |
345 | case Opt_sec_none: |
346 | pseudoflavor = RPC_AUTH_NULL; | |
347 | break; | |
348 | case Opt_sec_sys: | |
349 | pseudoflavor = RPC_AUTH_UNIX; | |
350 | break; | |
351 | case Opt_sec_krb5: | |
352 | pseudoflavor = RPC_AUTH_GSS_KRB5; | |
353 | break; | |
354 | case Opt_sec_krb5i: | |
355 | pseudoflavor = RPC_AUTH_GSS_KRB5I; | |
356 | break; | |
357 | case Opt_sec_krb5p: | |
358 | pseudoflavor = RPC_AUTH_GSS_KRB5P; | |
359 | break; | |
360 | case Opt_sec_lkey: | |
361 | pseudoflavor = RPC_AUTH_GSS_LKEY; | |
362 | break; | |
363 | case Opt_sec_lkeyi: | |
364 | pseudoflavor = RPC_AUTH_GSS_LKEYI; | |
365 | break; | |
366 | case Opt_sec_lkeyp: | |
367 | pseudoflavor = RPC_AUTH_GSS_LKEYP; | |
368 | break; | |
369 | case Opt_sec_spkm: | |
370 | pseudoflavor = RPC_AUTH_GSS_SPKM; | |
371 | break; | |
372 | case Opt_sec_spkmi: | |
373 | pseudoflavor = RPC_AUTH_GSS_SPKMI; | |
374 | break; | |
375 | case Opt_sec_spkmp: | |
376 | pseudoflavor = RPC_AUTH_GSS_SPKMP; | |
377 | break; | |
378 | default: | |
ce8866f0 | 379 | return nfs_invalf(fc, "NFS: sec=%s option not recognized", p); |
9954bf92 DH |
380 | } |
381 | ||
62a55d08 | 382 | ret = nfs_auth_info_add(fc, &ctx->auth_info, pseudoflavor); |
e558100f DH |
383 | if (ret < 0) |
384 | return ret; | |
9954bf92 DH |
385 | } |
386 | ||
e558100f | 387 | return 0; |
9954bf92 DH |
388 | } |
389 | ||
62a55d08 | 390 | static int nfs_parse_version_string(struct fs_context *fc, |
e38bb238 | 391 | const char *string) |
9954bf92 | 392 | { |
62a55d08 SM |
393 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
394 | ||
5eb005ca | 395 | ctx->flags &= ~NFS_MOUNT_VER3; |
e38bb238 | 396 | switch (lookup_constant(nfs_vers_tokens, string, -1)) { |
9954bf92 | 397 | case Opt_vers_2: |
5eb005ca | 398 | ctx->version = 2; |
9954bf92 DH |
399 | break; |
400 | case Opt_vers_3: | |
5eb005ca DH |
401 | ctx->flags |= NFS_MOUNT_VER3; |
402 | ctx->version = 3; | |
9954bf92 DH |
403 | break; |
404 | case Opt_vers_4: | |
405 | /* Backward compatibility option. In future, | |
406 | * the mount program should always supply | |
407 | * a NFSv4 minor version number. | |
408 | */ | |
5eb005ca | 409 | ctx->version = 4; |
9954bf92 DH |
410 | break; |
411 | case Opt_vers_4_0: | |
5eb005ca DH |
412 | ctx->version = 4; |
413 | ctx->minorversion = 0; | |
9954bf92 DH |
414 | break; |
415 | case Opt_vers_4_1: | |
5eb005ca DH |
416 | ctx->version = 4; |
417 | ctx->minorversion = 1; | |
9954bf92 DH |
418 | break; |
419 | case Opt_vers_4_2: | |
5eb005ca DH |
420 | ctx->version = 4; |
421 | ctx->minorversion = 2; | |
9954bf92 DH |
422 | break; |
423 | default: | |
ce8866f0 | 424 | return nfs_invalf(fc, "NFS: Unsupported NFS version"); |
9954bf92 | 425 | } |
e558100f | 426 | return 0; |
9954bf92 DH |
427 | } |
428 | ||
9954bf92 | 429 | /* |
e38bb238 | 430 | * Parse a single mount parameter. |
9954bf92 | 431 | */ |
f2aedb71 | 432 | static int nfs_fs_context_parse_param(struct fs_context *fc, |
e38bb238 | 433 | struct fs_parameter *param) |
9954bf92 | 434 | { |
e38bb238 | 435 | struct fs_parse_result result; |
f2aedb71 | 436 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
e38bb238 SM |
437 | unsigned short protofamily, mountfamily; |
438 | unsigned int len; | |
439 | int ret, opt; | |
9954bf92 | 440 | |
e38bb238 | 441 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", param->key); |
9954bf92 | 442 | |
d7167b14 | 443 | opt = fs_parse(fc, nfs_fs_parameters, param, &result); |
e38bb238 SM |
444 | if (opt < 0) |
445 | return ctx->sloppy ? 1 : opt; | |
446 | ||
447 | switch (opt) { | |
f2aedb71 | 448 | case Opt_source: |
ce8866f0 SM |
449 | if (fc->source) |
450 | return nfs_invalf(fc, "NFS: Multiple sources not supported"); | |
f2aedb71 DH |
451 | fc->source = param->string; |
452 | param->string = NULL; | |
453 | break; | |
454 | ||
9954bf92 DH |
455 | /* |
456 | * boolean options: foo/nofoo | |
457 | */ | |
cbd071b5 DH |
458 | case Opt_soft: |
459 | ctx->flags |= NFS_MOUNT_SOFT; | |
460 | ctx->flags &= ~NFS_MOUNT_SOFTERR; | |
461 | break; | |
462 | case Opt_softerr: | |
c74dfe97 | 463 | ctx->flags |= NFS_MOUNT_SOFTERR | NFS_MOUNT_SOFTREVAL; |
cbd071b5 DH |
464 | ctx->flags &= ~NFS_MOUNT_SOFT; |
465 | break; | |
466 | case Opt_hard: | |
c74dfe97 TM |
467 | ctx->flags &= ~(NFS_MOUNT_SOFT | |
468 | NFS_MOUNT_SOFTERR | | |
469 | NFS_MOUNT_SOFTREVAL); | |
470 | break; | |
471 | case Opt_softreval: | |
472 | if (result.negated) | |
473 | ctx->flags &= ~NFS_MOUNT_SOFTREVAL; | |
474 | else | |
475 | ctx->flags &= NFS_MOUNT_SOFTREVAL; | |
cbd071b5 DH |
476 | break; |
477 | case Opt_posix: | |
e38bb238 SM |
478 | if (result.negated) |
479 | ctx->flags &= ~NFS_MOUNT_POSIX; | |
480 | else | |
481 | ctx->flags |= NFS_MOUNT_POSIX; | |
cbd071b5 DH |
482 | break; |
483 | case Opt_cto: | |
e38bb238 SM |
484 | if (result.negated) |
485 | ctx->flags |= NFS_MOUNT_NOCTO; | |
486 | else | |
487 | ctx->flags &= ~NFS_MOUNT_NOCTO; | |
cbd071b5 DH |
488 | break; |
489 | case Opt_ac: | |
e38bb238 SM |
490 | if (result.negated) |
491 | ctx->flags |= NFS_MOUNT_NOAC; | |
492 | else | |
493 | ctx->flags &= ~NFS_MOUNT_NOAC; | |
cbd071b5 DH |
494 | break; |
495 | case Opt_lock: | |
e38bb238 SM |
496 | if (result.negated) { |
497 | ctx->flags |= NFS_MOUNT_NONLM; | |
498 | ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL); | |
499 | } else { | |
500 | ctx->flags &= ~NFS_MOUNT_NONLM; | |
501 | ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL); | |
502 | } | |
cbd071b5 DH |
503 | break; |
504 | case Opt_udp: | |
505 | ctx->flags &= ~NFS_MOUNT_TCP; | |
506 | ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP; | |
507 | break; | |
508 | case Opt_tcp: | |
509 | ctx->flags |= NFS_MOUNT_TCP; | |
510 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; | |
511 | break; | |
512 | case Opt_rdma: | |
513 | ctx->flags |= NFS_MOUNT_TCP; /* for side protocols */ | |
514 | ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA; | |
e38bb238 | 515 | xprt_load_transport(param->key); |
cbd071b5 DH |
516 | break; |
517 | case Opt_acl: | |
e38bb238 SM |
518 | if (result.negated) |
519 | ctx->flags |= NFS_MOUNT_NOACL; | |
520 | else | |
521 | ctx->flags &= ~NFS_MOUNT_NOACL; | |
cbd071b5 DH |
522 | break; |
523 | case Opt_rdirplus: | |
e38bb238 SM |
524 | if (result.negated) |
525 | ctx->flags |= NFS_MOUNT_NORDIRPLUS; | |
526 | else | |
527 | ctx->flags &= ~NFS_MOUNT_NORDIRPLUS; | |
cbd071b5 DH |
528 | break; |
529 | case Opt_sharecache: | |
e38bb238 SM |
530 | if (result.negated) |
531 | ctx->flags |= NFS_MOUNT_UNSHARED; | |
532 | else | |
533 | ctx->flags &= ~NFS_MOUNT_UNSHARED; | |
cbd071b5 DH |
534 | break; |
535 | case Opt_resvport: | |
e38bb238 SM |
536 | if (result.negated) |
537 | ctx->flags |= NFS_MOUNT_NORESVPORT; | |
538 | else | |
539 | ctx->flags &= ~NFS_MOUNT_NORESVPORT; | |
cbd071b5 | 540 | break; |
48ce73b1 | 541 | case Opt_fscache_flag: |
e38bb238 SM |
542 | if (result.negated) |
543 | ctx->options &= ~NFS_OPTION_FSCACHE; | |
544 | else | |
545 | ctx->options |= NFS_OPTION_FSCACHE; | |
48ce73b1 AV |
546 | kfree(ctx->fscache_uniq); |
547 | ctx->fscache_uniq = NULL; | |
548 | break; | |
549 | case Opt_fscache: | |
550 | ctx->options |= NFS_OPTION_FSCACHE; | |
551 | kfree(ctx->fscache_uniq); | |
552 | ctx->fscache_uniq = param->string; | |
553 | param->string = NULL; | |
cbd071b5 DH |
554 | break; |
555 | case Opt_migration: | |
e38bb238 SM |
556 | if (result.negated) |
557 | ctx->options &= ~NFS_OPTION_MIGRATION; | |
558 | else | |
559 | ctx->options |= NFS_OPTION_MIGRATION; | |
cbd071b5 | 560 | break; |
9954bf92 DH |
561 | |
562 | /* | |
563 | * options that take numeric values | |
564 | */ | |
cbd071b5 | 565 | case Opt_port: |
e38bb238 SM |
566 | if (result.uint_32 > USHRT_MAX) |
567 | goto out_of_bounds; | |
568 | ctx->nfs_server.port = result.uint_32; | |
cbd071b5 DH |
569 | break; |
570 | case Opt_rsize: | |
e38bb238 | 571 | ctx->rsize = result.uint_32; |
cbd071b5 DH |
572 | break; |
573 | case Opt_wsize: | |
e38bb238 | 574 | ctx->wsize = result.uint_32; |
cbd071b5 DH |
575 | break; |
576 | case Opt_bsize: | |
e38bb238 | 577 | ctx->bsize = result.uint_32; |
cbd071b5 DH |
578 | break; |
579 | case Opt_timeo: | |
e38bb238 SM |
580 | if (result.uint_32 < 1 || result.uint_32 > INT_MAX) |
581 | goto out_of_bounds; | |
582 | ctx->timeo = result.uint_32; | |
cbd071b5 DH |
583 | break; |
584 | case Opt_retrans: | |
e38bb238 SM |
585 | if (result.uint_32 > INT_MAX) |
586 | goto out_of_bounds; | |
587 | ctx->retrans = result.uint_32; | |
cbd071b5 DH |
588 | break; |
589 | case Opt_acregmin: | |
e38bb238 | 590 | ctx->acregmin = result.uint_32; |
cbd071b5 DH |
591 | break; |
592 | case Opt_acregmax: | |
e38bb238 | 593 | ctx->acregmax = result.uint_32; |
cbd071b5 DH |
594 | break; |
595 | case Opt_acdirmin: | |
e38bb238 | 596 | ctx->acdirmin = result.uint_32; |
cbd071b5 DH |
597 | break; |
598 | case Opt_acdirmax: | |
e38bb238 | 599 | ctx->acdirmax = result.uint_32; |
cbd071b5 DH |
600 | break; |
601 | case Opt_actimeo: | |
e38bb238 SM |
602 | ctx->acregmin = result.uint_32; |
603 | ctx->acregmax = result.uint_32; | |
604 | ctx->acdirmin = result.uint_32; | |
605 | ctx->acdirmax = result.uint_32; | |
cbd071b5 DH |
606 | break; |
607 | case Opt_namelen: | |
e38bb238 | 608 | ctx->namlen = result.uint_32; |
cbd071b5 DH |
609 | break; |
610 | case Opt_mountport: | |
e38bb238 SM |
611 | if (result.uint_32 > USHRT_MAX) |
612 | goto out_of_bounds; | |
613 | ctx->mount_server.port = result.uint_32; | |
cbd071b5 DH |
614 | break; |
615 | case Opt_mountvers: | |
e38bb238 SM |
616 | if (result.uint_32 < NFS_MNT_VERSION || |
617 | result.uint_32 > NFS_MNT3_VERSION) | |
618 | goto out_of_bounds; | |
619 | ctx->mount_server.version = result.uint_32; | |
cbd071b5 DH |
620 | break; |
621 | case Opt_minorversion: | |
e38bb238 SM |
622 | if (result.uint_32 > NFS4_MAX_MINOR_VERSION) |
623 | goto out_of_bounds; | |
624 | ctx->minorversion = result.uint_32; | |
cbd071b5 | 625 | break; |
9954bf92 DH |
626 | |
627 | /* | |
628 | * options that take text values | |
629 | */ | |
e38bb238 | 630 | case Opt_v: |
62a55d08 | 631 | ret = nfs_parse_version_string(fc, param->key + 1); |
e38bb238 SM |
632 | if (ret < 0) |
633 | return ret; | |
634 | break; | |
635 | case Opt_vers: | |
62a55d08 | 636 | ret = nfs_parse_version_string(fc, param->string); |
e558100f DH |
637 | if (ret < 0) |
638 | return ret; | |
cbd071b5 DH |
639 | break; |
640 | case Opt_sec: | |
62a55d08 | 641 | ret = nfs_parse_security_flavors(fc, param); |
e558100f DH |
642 | if (ret < 0) |
643 | return ret; | |
cbd071b5 | 644 | break; |
cbd071b5 | 645 | |
e38bb238 SM |
646 | case Opt_proto: |
647 | protofamily = AF_INET; | |
648 | switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) { | |
cbd071b5 | 649 | case Opt_xprt_udp6: |
e38bb238 | 650 | protofamily = AF_INET6; |
cbd071b5 DH |
651 | /* fall through */ |
652 | case Opt_xprt_udp: | |
653 | ctx->flags &= ~NFS_MOUNT_TCP; | |
654 | ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP; | |
9954bf92 | 655 | break; |
cbd071b5 | 656 | case Opt_xprt_tcp6: |
e38bb238 | 657 | protofamily = AF_INET6; |
cbd071b5 DH |
658 | /* fall through */ |
659 | case Opt_xprt_tcp: | |
660 | ctx->flags |= NFS_MOUNT_TCP; | |
661 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; | |
9954bf92 | 662 | break; |
cbd071b5 | 663 | case Opt_xprt_rdma6: |
e38bb238 | 664 | protofamily = AF_INET6; |
cbd071b5 DH |
665 | /* fall through */ |
666 | case Opt_xprt_rdma: | |
667 | /* vector side protocols to TCP */ | |
668 | ctx->flags |= NFS_MOUNT_TCP; | |
669 | ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA; | |
e38bb238 | 670 | xprt_load_transport(param->string); |
9954bf92 | 671 | break; |
cbd071b5 | 672 | default: |
ce8866f0 | 673 | return nfs_invalf(fc, "NFS: Unrecognized transport protocol"); |
cbd071b5 | 674 | } |
e38bb238 SM |
675 | |
676 | ctx->protofamily = protofamily; | |
cbd071b5 | 677 | break; |
e38bb238 | 678 | |
cbd071b5 | 679 | case Opt_mountproto: |
e38bb238 SM |
680 | mountfamily = AF_INET; |
681 | switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) { | |
cbd071b5 | 682 | case Opt_xprt_udp6: |
e38bb238 | 683 | mountfamily = AF_INET6; |
cbd071b5 DH |
684 | /* fall through */ |
685 | case Opt_xprt_udp: | |
686 | ctx->mount_server.protocol = XPRT_TRANSPORT_UDP; | |
687 | break; | |
688 | case Opt_xprt_tcp6: | |
e38bb238 | 689 | mountfamily = AF_INET6; |
cbd071b5 DH |
690 | /* fall through */ |
691 | case Opt_xprt_tcp: | |
692 | ctx->mount_server.protocol = XPRT_TRANSPORT_TCP; | |
693 | break; | |
694 | case Opt_xprt_rdma: /* not used for side protocols */ | |
695 | default: | |
ce8866f0 | 696 | return nfs_invalf(fc, "NFS: Unrecognized transport protocol"); |
cbd071b5 | 697 | } |
e38bb238 | 698 | ctx->mountfamily = mountfamily; |
cbd071b5 | 699 | break; |
e38bb238 | 700 | |
cbd071b5 | 701 | case Opt_addr: |
62a55d08 | 702 | len = rpc_pton(fc->net_ns, param->string, param->size, |
e38bb238 SM |
703 | &ctx->nfs_server.address, |
704 | sizeof(ctx->nfs_server._address)); | |
705 | if (len == 0) | |
cbd071b5 | 706 | goto out_invalid_address; |
e38bb238 | 707 | ctx->nfs_server.addrlen = len; |
cbd071b5 DH |
708 | break; |
709 | case Opt_clientaddr: | |
e38bb238 SM |
710 | kfree(ctx->client_address); |
711 | ctx->client_address = param->string; | |
712 | param->string = NULL; | |
cbd071b5 DH |
713 | break; |
714 | case Opt_mounthost: | |
e38bb238 SM |
715 | kfree(ctx->mount_server.hostname); |
716 | ctx->mount_server.hostname = param->string; | |
717 | param->string = NULL; | |
cbd071b5 DH |
718 | break; |
719 | case Opt_mountaddr: | |
62a55d08 | 720 | len = rpc_pton(fc->net_ns, param->string, param->size, |
e38bb238 SM |
721 | &ctx->mount_server.address, |
722 | sizeof(ctx->mount_server._address)); | |
723 | if (len == 0) | |
cbd071b5 | 724 | goto out_invalid_address; |
e38bb238 | 725 | ctx->mount_server.addrlen = len; |
cbd071b5 DH |
726 | break; |
727 | case Opt_nconnect: | |
e38bb238 SM |
728 | if (result.uint_32 < 1 || result.uint_32 > NFS_MAX_CONNECTIONS) |
729 | goto out_of_bounds; | |
730 | ctx->nfs_server.nconnect = result.uint_32; | |
cbd071b5 DH |
731 | break; |
732 | case Opt_lookupcache: | |
e38bb238 | 733 | switch (result.uint_32) { |
cbd071b5 DH |
734 | case Opt_lookupcache_all: |
735 | ctx->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE); | |
9954bf92 | 736 | break; |
cbd071b5 DH |
737 | case Opt_lookupcache_positive: |
738 | ctx->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE; | |
739 | ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG; | |
9954bf92 | 740 | break; |
cbd071b5 DH |
741 | case Opt_lookupcache_none: |
742 | ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE; | |
9954bf92 | 743 | break; |
cbd071b5 | 744 | default: |
e38bb238 | 745 | goto out_invalid_value; |
cbd071b5 DH |
746 | } |
747 | break; | |
cbd071b5 | 748 | case Opt_local_lock: |
e38bb238 | 749 | switch (result.uint_32) { |
cbd071b5 DH |
750 | case Opt_local_lock_all: |
751 | ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | | |
752 | NFS_MOUNT_LOCAL_FCNTL); | |
9954bf92 | 753 | break; |
cbd071b5 DH |
754 | case Opt_local_lock_flock: |
755 | ctx->flags |= NFS_MOUNT_LOCAL_FLOCK; | |
9954bf92 | 756 | break; |
cbd071b5 DH |
757 | case Opt_local_lock_posix: |
758 | ctx->flags |= NFS_MOUNT_LOCAL_FCNTL; | |
9954bf92 | 759 | break; |
cbd071b5 DH |
760 | case Opt_local_lock_none: |
761 | ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | | |
762 | NFS_MOUNT_LOCAL_FCNTL); | |
9954bf92 | 763 | break; |
cbd071b5 | 764 | default: |
e38bb238 | 765 | goto out_invalid_value; |
cbd071b5 DH |
766 | } |
767 | break; | |
9954bf92 DH |
768 | |
769 | /* | |
770 | * Special options | |
771 | */ | |
cbd071b5 | 772 | case Opt_sloppy: |
e38bb238 | 773 | ctx->sloppy = true; |
cbd071b5 DH |
774 | dfprintk(MOUNT, "NFS: relaxing parsing rules\n"); |
775 | break; | |
9954bf92 DH |
776 | } |
777 | ||
f8ee01e3 DH |
778 | return 0; |
779 | ||
f8ee01e3 | 780 | out_invalid_value: |
ce8866f0 | 781 | return nfs_invalf(fc, "NFS: Bad mount option value specified"); |
e38bb238 | 782 | out_invalid_address: |
ce8866f0 | 783 | return nfs_invalf(fc, "NFS: Bad IP address specified"); |
e38bb238 | 784 | out_of_bounds: |
3a21409a | 785 | return nfs_invalf(fc, "NFS: Value for '%s' out of range", param->key); |
e38bb238 SM |
786 | } |
787 | ||
9954bf92 | 788 | /* |
62a55d08 | 789 | * Split fc->source into "hostname:export_path". |
9954bf92 DH |
790 | * |
791 | * The leftmost colon demarks the split between the server's hostname | |
792 | * and the export path. If the hostname starts with a left square | |
793 | * bracket, then it may contain colons. | |
794 | * | |
795 | * Note: caller frees hostname and export path, even on error. | |
796 | */ | |
62a55d08 SM |
797 | static int nfs_parse_source(struct fs_context *fc, |
798 | size_t maxnamlen, size_t maxpathlen) | |
9954bf92 | 799 | { |
62a55d08 SM |
800 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
801 | const char *dev_name = fc->source; | |
9954bf92 | 802 | size_t len; |
62a55d08 | 803 | const char *end; |
9954bf92 DH |
804 | |
805 | if (unlikely(!dev_name || !*dev_name)) { | |
806 | dfprintk(MOUNT, "NFS: device name not specified\n"); | |
807 | return -EINVAL; | |
808 | } | |
809 | ||
810 | /* Is the host name protected with square brakcets? */ | |
811 | if (*dev_name == '[') { | |
812 | end = strchr(++dev_name, ']'); | |
813 | if (end == NULL || end[1] != ':') | |
814 | goto out_bad_devname; | |
815 | ||
816 | len = end - dev_name; | |
817 | end++; | |
818 | } else { | |
62a55d08 | 819 | const char *comma; |
9954bf92 DH |
820 | |
821 | end = strchr(dev_name, ':'); | |
822 | if (end == NULL) | |
823 | goto out_bad_devname; | |
824 | len = end - dev_name; | |
825 | ||
826 | /* kill possible hostname list: not supported */ | |
62a55d08 SM |
827 | comma = memchr(dev_name, ',', len); |
828 | if (comma) | |
9954bf92 DH |
829 | len = comma - dev_name; |
830 | } | |
831 | ||
832 | if (len > maxnamlen) | |
833 | goto out_hostname; | |
834 | ||
75a9b917 SM |
835 | kfree(ctx->nfs_server.hostname); |
836 | ||
9954bf92 | 837 | /* N.B. caller will free nfs_server.hostname in all cases */ |
e558100f DH |
838 | ctx->nfs_server.hostname = kmemdup_nul(dev_name, len, GFP_KERNEL); |
839 | if (!ctx->nfs_server.hostname) | |
9954bf92 DH |
840 | goto out_nomem; |
841 | len = strlen(++end); | |
842 | if (len > maxpathlen) | |
843 | goto out_path; | |
e558100f DH |
844 | ctx->nfs_server.export_path = kmemdup_nul(end, len, GFP_KERNEL); |
845 | if (!ctx->nfs_server.export_path) | |
9954bf92 DH |
846 | goto out_nomem; |
847 | ||
e558100f | 848 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", ctx->nfs_server.export_path); |
9954bf92 DH |
849 | return 0; |
850 | ||
851 | out_bad_devname: | |
ce8866f0 | 852 | return nfs_invalf(fc, "NFS: device name not in host:path format"); |
9954bf92 | 853 | out_nomem: |
ce8866f0 | 854 | nfs_errorf(fc, "NFS: not enough memory to parse device name"); |
9954bf92 | 855 | return -ENOMEM; |
9954bf92 | 856 | out_hostname: |
ce8866f0 | 857 | nfs_errorf(fc, "NFS: server hostname too long"); |
9954bf92 | 858 | return -ENAMETOOLONG; |
9954bf92 | 859 | out_path: |
ce8866f0 | 860 | nfs_errorf(fc, "NFS: export pathname too long"); |
9954bf92 DH |
861 | return -ENAMETOOLONG; |
862 | } | |
863 | ||
f2aedb71 DH |
864 | static inline bool is_remount_fc(struct fs_context *fc) |
865 | { | |
866 | return fc->root != NULL; | |
867 | } | |
868 | ||
9954bf92 | 869 | /* |
e558100f | 870 | * Parse monolithic NFS2/NFS3 mount data |
9954bf92 DH |
871 | * - fills in the mount root filehandle |
872 | * | |
873 | * For option strings, user space handles the following behaviors: | |
874 | * | |
875 | * + DNS: mapping server host name to IP address ("addr=" option) | |
876 | * | |
877 | * + failure mode: how to behave if a mount request can't be handled | |
878 | * immediately ("fg/bg" option) | |
879 | * | |
880 | * + retry: how often to retry a mount request ("retry=" option) | |
881 | * | |
882 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, | |
883 | * mountproto=tcp after mountproto=udp, and so on | |
884 | */ | |
f2aedb71 DH |
885 | static int nfs23_parse_monolithic(struct fs_context *fc, |
886 | struct nfs_mount_data *data) | |
9954bf92 | 887 | { |
f2aedb71 | 888 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
62a55d08 | 889 | struct nfs_fh *mntfh = ctx->mntfh; |
5eb005ca | 890 | struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; |
9954bf92 DH |
891 | int extra_flags = NFS_MOUNT_LEGACY_INTERFACE; |
892 | ||
893 | if (data == NULL) | |
894 | goto out_no_data; | |
895 | ||
5eb005ca | 896 | ctx->version = NFS_DEFAULT_VERSION; |
9954bf92 DH |
897 | switch (data->version) { |
898 | case 1: | |
899 | data->namlen = 0; /* fall through */ | |
900 | case 2: | |
901 | data->bsize = 0; /* fall through */ | |
902 | case 3: | |
903 | if (data->flags & NFS_MOUNT_VER3) | |
904 | goto out_no_v3; | |
905 | data->root.size = NFS2_FHSIZE; | |
906 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); | |
907 | /* Turn off security negotiation */ | |
908 | extra_flags |= NFS_MOUNT_SECFLAVOUR; | |
909 | /* fall through */ | |
910 | case 4: | |
911 | if (data->flags & NFS_MOUNT_SECFLAVOUR) | |
912 | goto out_no_sec; | |
913 | /* fall through */ | |
914 | case 5: | |
915 | memset(data->context, 0, sizeof(data->context)); | |
916 | /* fall through */ | |
917 | case 6: | |
918 | if (data->flags & NFS_MOUNT_VER3) { | |
919 | if (data->root.size > NFS3_FHSIZE || data->root.size == 0) | |
920 | goto out_invalid_fh; | |
921 | mntfh->size = data->root.size; | |
5eb005ca | 922 | ctx->version = 3; |
9954bf92 DH |
923 | } else { |
924 | mntfh->size = NFS2_FHSIZE; | |
5eb005ca | 925 | ctx->version = 2; |
9954bf92 DH |
926 | } |
927 | ||
928 | ||
929 | memcpy(mntfh->data, data->root.data, mntfh->size); | |
930 | if (mntfh->size < sizeof(mntfh->data)) | |
931 | memset(mntfh->data + mntfh->size, 0, | |
932 | sizeof(mntfh->data) - mntfh->size); | |
933 | ||
934 | /* | |
5eb005ca | 935 | * Translate to nfs_fs_context, which nfs_fill_super |
9954bf92 DH |
936 | * can deal with. |
937 | */ | |
5eb005ca DH |
938 | ctx->flags = data->flags & NFS_MOUNT_FLAGMASK; |
939 | ctx->flags |= extra_flags; | |
940 | ctx->rsize = data->rsize; | |
941 | ctx->wsize = data->wsize; | |
942 | ctx->timeo = data->timeo; | |
943 | ctx->retrans = data->retrans; | |
944 | ctx->acregmin = data->acregmin; | |
945 | ctx->acregmax = data->acregmax; | |
946 | ctx->acdirmin = data->acdirmin; | |
947 | ctx->acdirmax = data->acdirmax; | |
948 | ctx->need_mount = false; | |
9954bf92 DH |
949 | |
950 | memcpy(sap, &data->addr, sizeof(data->addr)); | |
5eb005ca DH |
951 | ctx->nfs_server.addrlen = sizeof(data->addr); |
952 | ctx->nfs_server.port = ntohs(data->addr.sin_port); | |
9954bf92 DH |
953 | if (sap->sa_family != AF_INET || |
954 | !nfs_verify_server_address(sap)) | |
955 | goto out_no_address; | |
956 | ||
957 | if (!(data->flags & NFS_MOUNT_TCP)) | |
5eb005ca | 958 | ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
9954bf92 | 959 | /* N.B. caller will free nfs_server.hostname in all cases */ |
5eb005ca | 960 | ctx->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
f2aedb71 DH |
961 | if (!ctx->nfs_server.hostname) |
962 | goto out_nomem; | |
963 | ||
5eb005ca DH |
964 | ctx->namlen = data->namlen; |
965 | ctx->bsize = data->bsize; | |
9954bf92 DH |
966 | |
967 | if (data->flags & NFS_MOUNT_SECFLAVOUR) | |
5eb005ca | 968 | ctx->selected_flavor = data->pseudoflavor; |
9954bf92 | 969 | else |
5eb005ca | 970 | ctx->selected_flavor = RPC_AUTH_UNIX; |
9954bf92 DH |
971 | |
972 | if (!(data->flags & NFS_MOUNT_NONLM)) | |
5eb005ca | 973 | ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK| |
9954bf92 DH |
974 | NFS_MOUNT_LOCAL_FCNTL); |
975 | else | |
5eb005ca | 976 | ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK| |
9954bf92 | 977 | NFS_MOUNT_LOCAL_FCNTL); |
62a55d08 | 978 | |
9954bf92 DH |
979 | /* |
980 | * The legacy version 6 binary mount data from userspace has a | |
981 | * field used only to transport selinux information into the | |
982 | * the kernel. To continue to support that functionality we | |
983 | * have a touch of selinux knowledge here in the NFS code. The | |
984 | * userspace code converted context=blah to just blah so we are | |
985 | * converting back to the full string selinux understands. | |
986 | */ | |
987 | if (data->context[0]){ | |
988 | #ifdef CONFIG_SECURITY_SELINUX | |
f2aedb71 DH |
989 | int ret; |
990 | ||
9954bf92 | 991 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
f2aedb71 DH |
992 | ret = vfs_parse_fs_string(fc, "context", |
993 | data->context, strlen(data->context)); | |
994 | if (ret < 0) | |
995 | return ret; | |
9954bf92 DH |
996 | #else |
997 | return -EINVAL; | |
998 | #endif | |
999 | } | |
1000 | ||
1001 | break; | |
1002 | default: | |
f2aedb71 | 1003 | goto generic; |
9954bf92 DH |
1004 | } |
1005 | ||
f2aedb71 | 1006 | ctx->skip_reconfig_option_check = true; |
9954bf92 DH |
1007 | return 0; |
1008 | ||
f2aedb71 DH |
1009 | generic: |
1010 | return generic_parse_monolithic(fc, data); | |
1011 | ||
9954bf92 | 1012 | out_no_data: |
f2aedb71 DH |
1013 | if (is_remount_fc(fc)) { |
1014 | ctx->skip_reconfig_option_check = true; | |
1015 | return 0; | |
1016 | } | |
ce8866f0 | 1017 | return nfs_invalf(fc, "NFS: mount program didn't pass any mount data"); |
9954bf92 DH |
1018 | |
1019 | out_no_v3: | |
ce8866f0 | 1020 | return nfs_invalf(fc, "NFS: nfs_mount_data version does not support v3"); |
9954bf92 DH |
1021 | |
1022 | out_no_sec: | |
ce8866f0 | 1023 | return nfs_invalf(fc, "NFS: nfs_mount_data version supports only AUTH_SYS"); |
9954bf92 DH |
1024 | |
1025 | out_nomem: | |
ce8866f0 | 1026 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options"); |
9954bf92 DH |
1027 | return -ENOMEM; |
1028 | ||
1029 | out_no_address: | |
ce8866f0 | 1030 | return nfs_invalf(fc, "NFS: mount program didn't pass remote address"); |
9954bf92 DH |
1031 | |
1032 | out_invalid_fh: | |
ce8866f0 | 1033 | return nfs_invalf(fc, "NFS: invalid root filehandle"); |
9954bf92 DH |
1034 | } |
1035 | ||
1036 | #if IS_ENABLED(CONFIG_NFS_V4) | |
9954bf92 DH |
1037 | /* |
1038 | * Validate NFSv4 mount options | |
1039 | */ | |
f2aedb71 DH |
1040 | static int nfs4_parse_monolithic(struct fs_context *fc, |
1041 | struct nfs4_mount_data *data) | |
9954bf92 | 1042 | { |
f2aedb71 | 1043 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
5eb005ca | 1044 | struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; |
9954bf92 DH |
1045 | char *c; |
1046 | ||
1047 | if (data == NULL) | |
1048 | goto out_no_data; | |
1049 | ||
5eb005ca | 1050 | ctx->version = 4; |
9954bf92 DH |
1051 | |
1052 | switch (data->version) { | |
1053 | case 1: | |
5eb005ca | 1054 | if (data->host_addrlen > sizeof(ctx->nfs_server.address)) |
9954bf92 DH |
1055 | goto out_no_address; |
1056 | if (data->host_addrlen == 0) | |
1057 | goto out_no_address; | |
5eb005ca | 1058 | ctx->nfs_server.addrlen = data->host_addrlen; |
9954bf92 DH |
1059 | if (copy_from_user(sap, data->host_addr, data->host_addrlen)) |
1060 | return -EFAULT; | |
1061 | if (!nfs_verify_server_address(sap)) | |
1062 | goto out_no_address; | |
5eb005ca | 1063 | ctx->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port); |
9954bf92 DH |
1064 | |
1065 | if (data->auth_flavourlen) { | |
1066 | rpc_authflavor_t pseudoflavor; | |
1067 | if (data->auth_flavourlen > 1) | |
1068 | goto out_inval_auth; | |
1069 | if (copy_from_user(&pseudoflavor, | |
1070 | data->auth_flavours, | |
1071 | sizeof(pseudoflavor))) | |
1072 | return -EFAULT; | |
5eb005ca | 1073 | ctx->selected_flavor = pseudoflavor; |
9954bf92 | 1074 | } else |
5eb005ca | 1075 | ctx->selected_flavor = RPC_AUTH_UNIX; |
9954bf92 DH |
1076 | |
1077 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); | |
1078 | if (IS_ERR(c)) | |
1079 | return PTR_ERR(c); | |
5eb005ca | 1080 | ctx->nfs_server.hostname = c; |
9954bf92 DH |
1081 | |
1082 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); | |
1083 | if (IS_ERR(c)) | |
1084 | return PTR_ERR(c); | |
5eb005ca | 1085 | ctx->nfs_server.export_path = c; |
9954bf92 DH |
1086 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
1087 | ||
1088 | c = strndup_user(data->client_addr.data, 16); | |
1089 | if (IS_ERR(c)) | |
1090 | return PTR_ERR(c); | |
5eb005ca | 1091 | ctx->client_address = c; |
9954bf92 DH |
1092 | |
1093 | /* | |
f2aedb71 | 1094 | * Translate to nfs_fs_context, which nfs_fill_super |
9954bf92 DH |
1095 | * can deal with. |
1096 | */ | |
1097 | ||
5eb005ca DH |
1098 | ctx->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
1099 | ctx->rsize = data->rsize; | |
1100 | ctx->wsize = data->wsize; | |
1101 | ctx->timeo = data->timeo; | |
1102 | ctx->retrans = data->retrans; | |
1103 | ctx->acregmin = data->acregmin; | |
1104 | ctx->acregmax = data->acregmax; | |
1105 | ctx->acdirmin = data->acdirmin; | |
1106 | ctx->acdirmax = data->acdirmax; | |
1107 | ctx->nfs_server.protocol = data->proto; | |
1108 | nfs_validate_transport_protocol(ctx); | |
1109 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) | |
9954bf92 DH |
1110 | goto out_invalid_transport_udp; |
1111 | ||
1112 | break; | |
1113 | default: | |
f2aedb71 | 1114 | goto generic; |
9954bf92 DH |
1115 | } |
1116 | ||
f2aedb71 | 1117 | ctx->skip_reconfig_option_check = true; |
9954bf92 DH |
1118 | return 0; |
1119 | ||
f2aedb71 DH |
1120 | generic: |
1121 | return generic_parse_monolithic(fc, data); | |
1122 | ||
9954bf92 | 1123 | out_no_data: |
f2aedb71 DH |
1124 | if (is_remount_fc(fc)) { |
1125 | ctx->skip_reconfig_option_check = true; | |
1126 | return 0; | |
1127 | } | |
ce8866f0 | 1128 | return nfs_invalf(fc, "NFS4: mount program didn't pass any mount data"); |
9954bf92 DH |
1129 | |
1130 | out_inval_auth: | |
ce8866f0 SM |
1131 | return nfs_invalf(fc, "NFS4: Invalid number of RPC auth flavours %d", |
1132 | data->auth_flavourlen); | |
9954bf92 DH |
1133 | |
1134 | out_no_address: | |
ce8866f0 | 1135 | return nfs_invalf(fc, "NFS4: mount program didn't pass remote address"); |
9954bf92 DH |
1136 | |
1137 | out_invalid_transport_udp: | |
aa3367c9 | 1138 | return nfs_invalf(fc, "NFS: Unsupported transport protocol udp"); |
9954bf92 | 1139 | } |
f2aedb71 | 1140 | #endif |
9954bf92 | 1141 | |
f2aedb71 DH |
1142 | /* |
1143 | * Parse a monolithic block of data from sys_mount(). | |
1144 | */ | |
1145 | static int nfs_fs_context_parse_monolithic(struct fs_context *fc, | |
1146 | void *data) | |
9954bf92 | 1147 | { |
f2aedb71 DH |
1148 | if (fc->fs_type == &nfs_fs_type) |
1149 | return nfs23_parse_monolithic(fc, data); | |
1150 | ||
1151 | #if IS_ENABLED(CONFIG_NFS_V4) | |
1152 | if (fc->fs_type == &nfs4_fs_type) | |
1153 | return nfs4_parse_monolithic(fc, data); | |
9954bf92 DH |
1154 | #endif |
1155 | ||
ce8866f0 | 1156 | return nfs_invalf(fc, "NFS: Unsupported monolithic data version"); |
f2aedb71 DH |
1157 | } |
1158 | ||
1159 | /* | |
1160 | * Validate the preparsed information in the config. | |
1161 | */ | |
1162 | static int nfs_fs_context_validate(struct fs_context *fc) | |
9954bf92 | 1163 | { |
f2aedb71 DH |
1164 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
1165 | struct nfs_subversion *nfs_mod; | |
1166 | struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; | |
9954bf92 DH |
1167 | int max_namelen = PAGE_SIZE; |
1168 | int max_pathlen = NFS_MAXPATHLEN; | |
f2aedb71 DH |
1169 | int port = 0; |
1170 | int ret; | |
9954bf92 | 1171 | |
f2aedb71 DH |
1172 | if (!fc->source) |
1173 | goto out_no_device_name; | |
1174 | ||
1175 | /* Check for sanity first. */ | |
1176 | if (ctx->minorversion && ctx->version != 4) | |
1177 | goto out_minorversion_mismatch; | |
1178 | ||
1179 | if (ctx->options & NFS_OPTION_MIGRATION && | |
1180 | (ctx->version != 4 || ctx->minorversion != 0)) | |
1181 | goto out_migration_misuse; | |
1182 | ||
1183 | /* Verify that any proto=/mountproto= options match the address | |
1184 | * families in the addr=/mountaddr= options. | |
1185 | */ | |
1186 | if (ctx->protofamily != AF_UNSPEC && | |
1187 | ctx->protofamily != ctx->nfs_server.address.sa_family) | |
1188 | goto out_proto_mismatch; | |
1189 | ||
1190 | if (ctx->mountfamily != AF_UNSPEC) { | |
1191 | if (ctx->mount_server.addrlen) { | |
1192 | if (ctx->mountfamily != ctx->mount_server.address.sa_family) | |
1193 | goto out_mountproto_mismatch; | |
1194 | } else { | |
1195 | if (ctx->mountfamily != ctx->nfs_server.address.sa_family) | |
1196 | goto out_mountproto_mismatch; | |
1197 | } | |
1198 | } | |
9954bf92 DH |
1199 | |
1200 | if (!nfs_verify_server_address(sap)) | |
1201 | goto out_no_address; | |
1202 | ||
5eb005ca | 1203 | if (ctx->version == 4) { |
62a55d08 SM |
1204 | if (IS_ENABLED(CONFIG_NFS_V4)) { |
1205 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_RDMA) | |
1206 | port = NFS_RDMA_PORT; | |
1207 | else | |
1208 | port = NFS_PORT; | |
1209 | max_namelen = NFS4_MAXNAMLEN; | |
1210 | max_pathlen = NFS4_MAXPATHLEN; | |
1211 | nfs_validate_transport_protocol(ctx); | |
1212 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) | |
1213 | goto out_invalid_transport_udp; | |
1214 | ctx->flags &= ~(NFS_MOUNT_NONLM | NFS_MOUNT_NOACL | | |
1215 | NFS_MOUNT_VER3 | NFS_MOUNT_LOCAL_FLOCK | | |
1216 | NFS_MOUNT_LOCAL_FCNTL); | |
1217 | } else { | |
1218 | goto out_v4_not_compiled; | |
1219 | } | |
9954bf92 | 1220 | } else { |
5eb005ca | 1221 | nfs_set_mount_transport_protocol(ctx); |
b24ee6c6 OK |
1222 | #ifdef CONFIG_NFS_DISABLE_UDP_SUPPORT |
1223 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) | |
1224 | goto out_invalid_transport_udp; | |
1225 | #endif | |
5eb005ca | 1226 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_RDMA) |
9954bf92 DH |
1227 | port = NFS_RDMA_PORT; |
1228 | } | |
1229 | ||
5eb005ca | 1230 | nfs_set_port(sap, &ctx->nfs_server.port, port); |
9954bf92 | 1231 | |
62a55d08 | 1232 | ret = nfs_parse_source(fc, max_namelen, max_pathlen); |
f2aedb71 DH |
1233 | if (ret < 0) |
1234 | return ret; | |
1235 | ||
1236 | /* Load the NFS protocol module if we haven't done so yet */ | |
62a55d08 | 1237 | if (!ctx->nfs_mod) { |
f2aedb71 DH |
1238 | nfs_mod = get_nfs_version(ctx->version); |
1239 | if (IS_ERR(nfs_mod)) { | |
1240 | ret = PTR_ERR(nfs_mod); | |
1241 | goto out_version_unavailable; | |
1242 | } | |
62a55d08 | 1243 | ctx->nfs_mod = nfs_mod; |
f2aedb71 | 1244 | } |
1cef2184 SM |
1245 | |
1246 | /* Ensure the filesystem context has the correct fs_type */ | |
1247 | if (fc->fs_type != ctx->nfs_mod->nfs_fs) { | |
1248 | module_put(fc->fs_type->owner); | |
1249 | __module_get(ctx->nfs_mod->nfs_fs->owner); | |
1250 | fc->fs_type = ctx->nfs_mod->nfs_fs; | |
1251 | } | |
f2aedb71 | 1252 | return 0; |
9954bf92 | 1253 | |
f2aedb71 | 1254 | out_no_device_name: |
ce8866f0 | 1255 | return nfs_invalf(fc, "NFS: Device name not specified"); |
9954bf92 | 1256 | out_v4_not_compiled: |
ce8866f0 | 1257 | nfs_errorf(fc, "NFS: NFSv4 is not compiled into kernel"); |
9954bf92 | 1258 | return -EPROTONOSUPPORT; |
9954bf92 | 1259 | out_invalid_transport_udp: |
aa3367c9 | 1260 | return nfs_invalf(fc, "NFS: Unsupported transport protocol udp"); |
9954bf92 | 1261 | out_no_address: |
ce8866f0 | 1262 | return nfs_invalf(fc, "NFS: mount program didn't pass remote address"); |
f2aedb71 | 1263 | out_mountproto_mismatch: |
ce8866f0 | 1264 | return nfs_invalf(fc, "NFS: Mount server address does not match mountproto= option"); |
f2aedb71 | 1265 | out_proto_mismatch: |
ce8866f0 | 1266 | return nfs_invalf(fc, "NFS: Server address does not match proto= option"); |
f2aedb71 | 1267 | out_minorversion_mismatch: |
ce8866f0 | 1268 | return nfs_invalf(fc, "NFS: Mount option vers=%u does not support minorversion=%u", |
f2aedb71 | 1269 | ctx->version, ctx->minorversion); |
f2aedb71 | 1270 | out_migration_misuse: |
ce8866f0 | 1271 | return nfs_invalf(fc, "NFS: 'Migration' not supported for this NFS version"); |
f2aedb71 | 1272 | out_version_unavailable: |
ce8866f0 | 1273 | nfs_errorf(fc, "NFS: Version unavailable"); |
f2aedb71 DH |
1274 | return ret; |
1275 | } | |
1276 | ||
1277 | /* | |
1278 | * Create an NFS superblock by the appropriate method. | |
1279 | */ | |
1280 | static int nfs_get_tree(struct fs_context *fc) | |
1281 | { | |
1282 | struct nfs_fs_context *ctx = nfs_fc2context(fc); | |
1283 | int err = nfs_fs_context_validate(fc); | |
1284 | ||
1285 | if (err) | |
1286 | return err; | |
1287 | if (!ctx->internal) | |
62a55d08 | 1288 | return ctx->nfs_mod->rpc_ops->try_get_tree(fc); |
f2aedb71 DH |
1289 | else |
1290 | return nfs_get_tree_common(fc); | |
9954bf92 | 1291 | } |
f2aedb71 DH |
1292 | |
1293 | /* | |
1294 | * Handle duplication of a configuration. The caller copied *src into *sc, but | |
1295 | * it can't deal with resource pointers in the filesystem context, so we have | |
1296 | * to do that. We need to clear pointers, copy data or get extra refs as | |
1297 | * appropriate. | |
1298 | */ | |
1299 | static int nfs_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc) | |
1300 | { | |
1301 | struct nfs_fs_context *src = nfs_fc2context(src_fc), *ctx; | |
1302 | ||
1303 | ctx = kmemdup(src, sizeof(struct nfs_fs_context), GFP_KERNEL); | |
1304 | if (!ctx) | |
1305 | return -ENOMEM; | |
1306 | ||
62a55d08 SM |
1307 | ctx->mntfh = nfs_alloc_fhandle(); |
1308 | if (!ctx->mntfh) { | |
f2aedb71 DH |
1309 | kfree(ctx); |
1310 | return -ENOMEM; | |
1311 | } | |
62a55d08 | 1312 | nfs_copy_fh(ctx->mntfh, src->mntfh); |
f2aedb71 | 1313 | |
62a55d08 | 1314 | __module_get(ctx->nfs_mod->owner); |
f2aedb71 DH |
1315 | ctx->client_address = NULL; |
1316 | ctx->mount_server.hostname = NULL; | |
1317 | ctx->nfs_server.export_path = NULL; | |
1318 | ctx->nfs_server.hostname = NULL; | |
1319 | ctx->fscache_uniq = NULL; | |
f2aedb71 DH |
1320 | ctx->clone_data.fattr = NULL; |
1321 | fc->fs_private = ctx; | |
1322 | return 0; | |
1323 | } | |
1324 | ||
1325 | static void nfs_fs_context_free(struct fs_context *fc) | |
1326 | { | |
1327 | struct nfs_fs_context *ctx = nfs_fc2context(fc); | |
1328 | ||
1329 | if (ctx) { | |
62a55d08 SM |
1330 | if (ctx->server) |
1331 | nfs_free_server(ctx->server); | |
1332 | if (ctx->nfs_mod) | |
1333 | put_nfs_version(ctx->nfs_mod); | |
f2aedb71 DH |
1334 | kfree(ctx->client_address); |
1335 | kfree(ctx->mount_server.hostname); | |
1336 | kfree(ctx->nfs_server.export_path); | |
1337 | kfree(ctx->nfs_server.hostname); | |
1338 | kfree(ctx->fscache_uniq); | |
62a55d08 | 1339 | nfs_free_fhandle(ctx->mntfh); |
f2aedb71 DH |
1340 | nfs_free_fattr(ctx->clone_data.fattr); |
1341 | kfree(ctx); | |
1342 | } | |
1343 | } | |
1344 | ||
1345 | static const struct fs_context_operations nfs_fs_context_ops = { | |
1346 | .free = nfs_fs_context_free, | |
1347 | .dup = nfs_fs_context_dup, | |
1348 | .parse_param = nfs_fs_context_parse_param, | |
1349 | .parse_monolithic = nfs_fs_context_parse_monolithic, | |
1350 | .get_tree = nfs_get_tree, | |
1351 | .reconfigure = nfs_reconfigure, | |
1352 | }; | |
1353 | ||
1354 | /* | |
1355 | * Prepare superblock configuration. We use the namespaces attached to the | |
1356 | * context. This may be the current process's namespaces, or it may be a | |
1357 | * container's namespaces. | |
1358 | */ | |
1359 | static int nfs_init_fs_context(struct fs_context *fc) | |
1360 | { | |
1361 | struct nfs_fs_context *ctx; | |
1362 | ||
1363 | ctx = kzalloc(sizeof(struct nfs_fs_context), GFP_KERNEL); | |
1364 | if (unlikely(!ctx)) | |
1365 | return -ENOMEM; | |
1366 | ||
62a55d08 SM |
1367 | ctx->mntfh = nfs_alloc_fhandle(); |
1368 | if (unlikely(!ctx->mntfh)) { | |
f2aedb71 DH |
1369 | kfree(ctx); |
1370 | return -ENOMEM; | |
1371 | } | |
1372 | ||
1373 | ctx->protofamily = AF_UNSPEC; | |
1374 | ctx->mountfamily = AF_UNSPEC; | |
1375 | ctx->mount_server.port = NFS_UNSPEC_PORT; | |
1376 | ||
1377 | if (fc->root) { | |
1378 | /* reconfigure, start with the current config */ | |
1379 | struct nfs_server *nfss = fc->root->d_sb->s_fs_info; | |
1380 | struct net *net = nfss->nfs_client->cl_net; | |
1381 | ||
1382 | ctx->flags = nfss->flags; | |
1383 | ctx->rsize = nfss->rsize; | |
1384 | ctx->wsize = nfss->wsize; | |
1385 | ctx->retrans = nfss->client->cl_timeout->to_retries; | |
1386 | ctx->selected_flavor = nfss->client->cl_auth->au_flavor; | |
1387 | ctx->acregmin = nfss->acregmin / HZ; | |
1388 | ctx->acregmax = nfss->acregmax / HZ; | |
1389 | ctx->acdirmin = nfss->acdirmin / HZ; | |
1390 | ctx->acdirmax = nfss->acdirmax / HZ; | |
1391 | ctx->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; | |
1392 | ctx->nfs_server.port = nfss->port; | |
1393 | ctx->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; | |
1394 | ctx->version = nfss->nfs_client->rpc_ops->version; | |
1395 | ctx->minorversion = nfss->nfs_client->cl_minorversion; | |
1396 | ||
1397 | memcpy(&ctx->nfs_server.address, &nfss->nfs_client->cl_addr, | |
1398 | ctx->nfs_server.addrlen); | |
1399 | ||
1400 | if (fc->net_ns != net) { | |
1401 | put_net(fc->net_ns); | |
1402 | fc->net_ns = get_net(net); | |
1403 | } | |
1404 | ||
62a55d08 SM |
1405 | ctx->nfs_mod = nfss->nfs_client->cl_nfs_mod; |
1406 | __module_get(ctx->nfs_mod->owner); | |
f2aedb71 DH |
1407 | } else { |
1408 | /* defaults */ | |
1409 | ctx->timeo = NFS_UNSPEC_TIMEO; | |
1410 | ctx->retrans = NFS_UNSPEC_RETRANS; | |
1411 | ctx->acregmin = NFS_DEF_ACREGMIN; | |
1412 | ctx->acregmax = NFS_DEF_ACREGMAX; | |
1413 | ctx->acdirmin = NFS_DEF_ACDIRMIN; | |
1414 | ctx->acdirmax = NFS_DEF_ACDIRMAX; | |
1415 | ctx->nfs_server.port = NFS_UNSPEC_PORT; | |
1416 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; | |
1417 | ctx->selected_flavor = RPC_AUTH_MAXFLAVOR; | |
1418 | ctx->minorversion = 0; | |
1419 | ctx->need_mount = true; | |
1420 | } | |
f2aedb71 DH |
1421 | fc->fs_private = ctx; |
1422 | fc->ops = &nfs_fs_context_ops; | |
1423 | return 0; | |
1424 | } | |
1425 | ||
1426 | struct file_system_type nfs_fs_type = { | |
1427 | .owner = THIS_MODULE, | |
1428 | .name = "nfs", | |
1429 | .init_fs_context = nfs_init_fs_context, | |
d7167b14 | 1430 | .parameters = nfs_fs_parameters, |
f2aedb71 DH |
1431 | .kill_sb = nfs_kill_super, |
1432 | .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA, | |
1433 | }; | |
1434 | MODULE_ALIAS_FS("nfs"); | |
1435 | EXPORT_SYMBOL_GPL(nfs_fs_type); | |
1436 | ||
1437 | #if IS_ENABLED(CONFIG_NFS_V4) | |
1438 | struct file_system_type nfs4_fs_type = { | |
1439 | .owner = THIS_MODULE, | |
1440 | .name = "nfs4", | |
1441 | .init_fs_context = nfs_init_fs_context, | |
d7167b14 | 1442 | .parameters = nfs_fs_parameters, |
f2aedb71 DH |
1443 | .kill_sb = nfs_kill_super, |
1444 | .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA, | |
1445 | }; | |
1446 | MODULE_ALIAS_FS("nfs4"); | |
1447 | MODULE_ALIAS("nfs4"); | |
1448 | EXPORT_SYMBOL_GPL(nfs4_fs_type); | |
1449 | #endif /* CONFIG_NFS_V4 */ |