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