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