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