| @@ -1,1161 +1,1160 @@ | | | @@ -1,1161 +1,1160 @@ |
1 | /* $NetBSD: nfs_vfsops.c,v 1.241 2020/04/13 19:23:20 ad Exp $ */ | | 1 | /* $NetBSD: nfs_vfsops.c,v 1.242 2021/04/02 03:07:54 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1989, 1993, 1995 | | 4 | * Copyright (c) 1989, 1993, 1995 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Rick Macklem at The University of Guelph. | | 8 | * Rick Macklem at The University of Guelph. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. Neither the name of the University nor the names of its contributors | | 18 | * 3. Neither the name of the University nor the names of its contributors |
19 | * may be used to endorse or promote products derived from this software | | 19 | * may be used to endorse or promote products derived from this software |
20 | * without specific prior written permission. | | 20 | * without specific prior written permission. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | * | | 33 | * |
34 | * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95 | | 34 | * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95 |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.241 2020/04/13 19:23:20 ad Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.242 2021/04/02 03:07:54 christos Exp $"); |
39 | | | 39 | |
40 | #if defined(_KERNEL_OPT) | | 40 | #if defined(_KERNEL_OPT) |
41 | #include "opt_nfs.h" | | 41 | #include "opt_nfs.h" |
42 | #endif | | 42 | #endif |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/ioctl.h> | | 45 | #include <sys/ioctl.h> |
46 | #include <sys/signal.h> | | 46 | #include <sys/signal.h> |
47 | #include <sys/proc.h> | | 47 | #include <sys/proc.h> |
48 | #include <sys/namei.h> | | 48 | #include <sys/namei.h> |
49 | #include <sys/device.h> | | 49 | #include <sys/device.h> |
50 | #include <sys/vnode.h> | | 50 | #include <sys/vnode.h> |
51 | #include <sys/kernel.h> | | 51 | #include <sys/kernel.h> |
52 | #include <sys/mount.h> | | 52 | #include <sys/mount.h> |
53 | #include <sys/buf.h> | | 53 | #include <sys/buf.h> |
54 | #include <sys/mbuf.h> | | 54 | #include <sys/mbuf.h> |
55 | #include <sys/dirent.h> | | 55 | #include <sys/dirent.h> |
56 | #include <sys/socket.h> | | 56 | #include <sys/socket.h> |
57 | #include <sys/socketvar.h> | | 57 | #include <sys/socketvar.h> |
58 | #include <sys/sysctl.h> | | 58 | #include <sys/sysctl.h> |
59 | #include <sys/systm.h> | | 59 | #include <sys/systm.h> |
60 | #include <sys/timetc.h> | | 60 | #include <sys/timetc.h> |
61 | #include <sys/kauth.h> | | 61 | #include <sys/kauth.h> |
62 | #include <sys/module.h> | | 62 | #include <sys/module.h> |
63 | | | 63 | |
64 | #include <net/if.h> | | 64 | #include <net/if.h> |
65 | #include <net/route.h> | | 65 | #include <net/route.h> |
66 | #include <netinet/in.h> | | 66 | #include <netinet/in.h> |
67 | | | 67 | |
68 | #include <nfs/rpcv2.h> | | 68 | #include <nfs/rpcv2.h> |
69 | #include <nfs/nfsproto.h> | | 69 | #include <nfs/nfsproto.h> |
70 | #include <nfs/nfsnode.h> | | 70 | #include <nfs/nfsnode.h> |
71 | #include <nfs/nfs.h> | | 71 | #include <nfs/nfs.h> |
72 | #include <nfs/nfsmount.h> | | 72 | #include <nfs/nfsmount.h> |
73 | #include <nfs/xdr_subs.h> | | 73 | #include <nfs/xdr_subs.h> |
74 | #include <nfs/nfsm_subs.h> | | 74 | #include <nfs/nfsm_subs.h> |
75 | #include <nfs/nfsdiskless.h> | | 75 | #include <nfs/nfsdiskless.h> |
76 | #include <nfs/nfs_var.h> | | 76 | #include <nfs/nfs_var.h> |
77 | | | 77 | |
78 | MODULE(MODULE_CLASS_VFS, nfs, NULL); | | 78 | MODULE(MODULE_CLASS_VFS, nfs, NULL); |
79 | | | 79 | |
80 | extern struct nfsstats nfsstats; | | 80 | extern struct nfsstats nfsstats; |
81 | extern int nfs_ticks; | | 81 | extern int nfs_ticks; |
82 | | | 82 | |
83 | /* | | 83 | /* |
84 | * keep a count of the nfs mounts to generate ficticious drive names | | 84 | * keep a count of the nfs mounts to generate ficticious drive names |
85 | * for the per drive stats. | | 85 | * for the per drive stats. |
86 | */ | | 86 | */ |
87 | unsigned int nfs_mount_count = 0; | | 87 | unsigned int nfs_mount_count = 0; |
88 | | | 88 | |
89 | int nfs_commitsize; | | 89 | int nfs_commitsize; |
90 | | | 90 | |
91 | /* | | 91 | /* |
92 | * nfs vfs operations. | | 92 | * nfs vfs operations. |
93 | */ | | 93 | */ |
94 | | | 94 | |
95 | extern const struct vnodeopv_desc nfsv2_vnodeop_opv_desc; | | 95 | extern const struct vnodeopv_desc nfsv2_vnodeop_opv_desc; |
96 | extern const struct vnodeopv_desc spec_nfsv2nodeop_opv_desc; | | 96 | extern const struct vnodeopv_desc spec_nfsv2nodeop_opv_desc; |
97 | extern const struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc; | | 97 | extern const struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc; |
98 | | | 98 | |
99 | const struct vnodeopv_desc * const nfs_vnodeopv_descs[] = { | | 99 | const struct vnodeopv_desc * const nfs_vnodeopv_descs[] = { |
100 | &nfsv2_vnodeop_opv_desc, | | 100 | &nfsv2_vnodeop_opv_desc, |
101 | &spec_nfsv2nodeop_opv_desc, | | 101 | &spec_nfsv2nodeop_opv_desc, |
102 | &fifo_nfsv2nodeop_opv_desc, | | 102 | &fifo_nfsv2nodeop_opv_desc, |
103 | NULL, | | 103 | NULL, |
104 | }; | | 104 | }; |
105 | | | 105 | |
106 | struct vfsops nfs_vfsops = { | | 106 | struct vfsops nfs_vfsops = { |
107 | .vfs_name = MOUNT_NFS, | | 107 | .vfs_name = MOUNT_NFS, |
108 | .vfs_min_mount_data = sizeof (struct nfs_args), | | 108 | .vfs_min_mount_data = sizeof (struct nfs_args), |
109 | .vfs_mount = nfs_mount, | | 109 | .vfs_mount = nfs_mount, |
110 | .vfs_start = nfs_start, | | 110 | .vfs_start = nfs_start, |
111 | .vfs_unmount = nfs_unmount, | | 111 | .vfs_unmount = nfs_unmount, |
112 | .vfs_root = nfs_root, | | 112 | .vfs_root = nfs_root, |
113 | .vfs_quotactl = (void *)eopnotsupp, | | 113 | .vfs_quotactl = (void *)eopnotsupp, |
114 | .vfs_statvfs = nfs_statvfs, | | 114 | .vfs_statvfs = nfs_statvfs, |
115 | .vfs_sync = nfs_sync, | | 115 | .vfs_sync = nfs_sync, |
116 | .vfs_loadvnode = nfs_loadvnode, | | 116 | .vfs_loadvnode = nfs_loadvnode, |
117 | .vfs_vget = nfs_vget, | | 117 | .vfs_vget = nfs_vget, |
118 | .vfs_fhtovp = nfs_fhtovp, | | 118 | .vfs_fhtovp = nfs_fhtovp, |
119 | .vfs_vptofh = nfs_vptofh, | | 119 | .vfs_vptofh = nfs_vptofh, |
120 | .vfs_init = nfs_vfs_init, | | 120 | .vfs_init = nfs_vfs_init, |
121 | .vfs_done = nfs_vfs_done, | | 121 | .vfs_done = nfs_vfs_done, |
122 | .vfs_mountroot = nfs_mountroot, | | 122 | .vfs_mountroot = nfs_mountroot, |
123 | .vfs_snapshot = (void *)eopnotsupp, | | 123 | .vfs_snapshot = (void *)eopnotsupp, |
124 | .vfs_extattrctl = vfs_stdextattrctl, | | 124 | .vfs_extattrctl = vfs_stdextattrctl, |
125 | .vfs_suspendctl = genfs_suspendctl, | | 125 | .vfs_suspendctl = genfs_suspendctl, |
126 | .vfs_renamelock_enter = genfs_renamelock_enter, | | 126 | .vfs_renamelock_enter = genfs_renamelock_enter, |
127 | .vfs_renamelock_exit = genfs_renamelock_exit, | | 127 | .vfs_renamelock_exit = genfs_renamelock_exit, |
128 | .vfs_fsync = (void *)eopnotsupp, | | 128 | .vfs_fsync = (void *)eopnotsupp, |
129 | .vfs_opv_descs = nfs_vnodeopv_descs | | 129 | .vfs_opv_descs = nfs_vnodeopv_descs |
130 | }; | | 130 | }; |
131 | | | 131 | |
132 | extern u_int32_t nfs_procids[NFS_NPROCS]; | | 132 | extern u_int32_t nfs_procids[NFS_NPROCS]; |
133 | extern u_int32_t nfs_prog, nfs_vers; | | 133 | extern u_int32_t nfs_prog, nfs_vers; |
134 | | | 134 | |
135 | static int nfs_mount_diskless(struct nfs_dlmount *, const char *, | | 135 | static int nfs_mount_diskless(struct nfs_dlmount *, const char *, |
136 | struct mount **, struct vnode **, struct lwp *); | | 136 | struct mount **, struct vnode **, struct lwp *); |
137 | | | 137 | |
138 | static int | | 138 | static int |
139 | nfs_modcmd(modcmd_t cmd, void *arg) | | 139 | nfs_modcmd(modcmd_t cmd, void *arg) |
140 | { | | 140 | { |
141 | int error; | | 141 | int error; |
142 | | | 142 | |
143 | switch (cmd) { | | 143 | switch (cmd) { |
144 | case MODULE_CMD_INIT: | | 144 | case MODULE_CMD_INIT: |
145 | error = vfs_attach(&nfs_vfsops); | | 145 | error = vfs_attach(&nfs_vfsops); |
146 | return error; | | 146 | return error; |
147 | case MODULE_CMD_FINI: | | 147 | case MODULE_CMD_FINI: |
148 | error = vfs_detach(&nfs_vfsops); | | 148 | error = vfs_detach(&nfs_vfsops); |
149 | return error; | | 149 | return error; |
150 | default: | | 150 | default: |
151 | return ENOTTY; | | 151 | return ENOTTY; |
152 | } | | 152 | } |
153 | } | | 153 | } |
154 | | | 154 | |
155 | /* | | 155 | /* |
156 | * nfs statvfs call | | 156 | * nfs statvfs call |
157 | */ | | 157 | */ |
158 | int | | 158 | int |
159 | nfs_statvfs(struct mount *mp, struct statvfs *sbp) | | 159 | nfs_statvfs(struct mount *mp, struct statvfs *sbp) |
160 | { | | 160 | { |
161 | struct lwp *l = curlwp; | | 161 | struct lwp *l = curlwp; |
162 | struct vnode *vp; | | 162 | struct vnode *vp; |
163 | struct nfs_statfs *sfp; | | 163 | struct nfs_statfs *sfp; |
164 | char *cp; | | 164 | char *cp; |
165 | u_int32_t *tl; | | 165 | u_int32_t *tl; |
166 | int32_t t1, t2; | | 166 | int32_t t1, t2; |
167 | char *bpos, *dpos, *cp2; | | 167 | char *bpos, *dpos, *cp2; |
168 | struct nfsmount *nmp = VFSTONFS(mp); | | 168 | struct nfsmount *nmp = VFSTONFS(mp); |
169 | int error = 0, retattr; | | 169 | int error = 0, retattr; |
170 | #ifdef NFS_V2_ONLY | | 170 | #ifdef NFS_V2_ONLY |
171 | const int v3 = 0; | | 171 | const int v3 = 0; |
172 | #else | | 172 | #else |
173 | int v3 = (nmp->nm_flag & NFSMNT_NFSV3); | | 173 | int v3 = (nmp->nm_flag & NFSMNT_NFSV3); |
174 | #endif | | 174 | #endif |
175 | struct mbuf *mreq, *mrep = NULL, *md, *mb; | | 175 | struct mbuf *mreq, *mrep = NULL, *md, *mb; |
176 | kauth_cred_t cred; | | 176 | kauth_cred_t cred; |
177 | u_quad_t tquad; | | 177 | u_quad_t tquad; |
178 | struct nfsnode *np; | | 178 | struct nfsnode *np; |
179 | | | 179 | |
180 | #ifndef nolint | | 180 | #ifndef nolint |
181 | sfp = (struct nfs_statfs *)0; | | 181 | sfp = (struct nfs_statfs *)0; |
182 | #endif | | 182 | #endif |
183 | vp = nmp->nm_vnode; | | 183 | vp = nmp->nm_vnode; |
184 | np = VTONFS(vp); | | 184 | np = VTONFS(vp); |
185 | cred = kauth_cred_alloc(); | | 185 | cred = kauth_cred_alloc(); |
186 | #ifndef NFS_V2_ONLY | | 186 | #ifndef NFS_V2_ONLY |
187 | if (v3 && (nmp->nm_iflag & NFSMNT_GOTFSINFO) == 0) | | 187 | if (v3 && (nmp->nm_iflag & NFSMNT_GOTFSINFO) == 0) |
188 | (void)nfs_fsinfo(nmp, vp, cred, l); | | 188 | (void)nfs_fsinfo(nmp, vp, cred, l); |
189 | #endif | | 189 | #endif |
190 | nfsstats.rpccnt[NFSPROC_FSSTAT]++; | | 190 | nfsstats.rpccnt[NFSPROC_FSSTAT]++; |
191 | nfsm_reqhead(np, NFSPROC_FSSTAT, NFSX_FH(v3)); | | 191 | nfsm_reqhead(np, NFSPROC_FSSTAT, NFSX_FH(v3)); |
192 | nfsm_fhtom(np, v3); | | 192 | nfsm_fhtom(np, v3); |
193 | nfsm_request(np, NFSPROC_FSSTAT, l, cred); | | 193 | nfsm_request(np, NFSPROC_FSSTAT, l, cred); |
194 | if (v3) | | 194 | if (v3) |
195 | nfsm_postop_attr(vp, retattr, 0); | | 195 | nfsm_postop_attr(vp, retattr, 0); |
196 | if (error) { | | 196 | if (error) { |
197 | if (mrep != NULL) { | | 197 | if (mrep != NULL) { |
198 | if (mrep->m_next != NULL) | | 198 | if (mrep->m_next != NULL) |
199 | printf("nfs_vfsops: nfs_statvfs would lose buffers\n"); | | 199 | printf("nfs_vfsops: nfs_statvfs would lose buffers\n"); |
200 | m_freem(mrep); | | 200 | m_freem(mrep); |
201 | } | | 201 | } |
202 | goto nfsmout; | | 202 | goto nfsmout; |
203 | } | | 203 | } |
204 | nfsm_dissect(sfp, struct nfs_statfs *, NFSX_STATFS(v3)); | | 204 | nfsm_dissect(sfp, struct nfs_statfs *, NFSX_STATFS(v3)); |
205 | sbp->f_flag = nmp->nm_flag; | | 205 | sbp->f_flag = nmp->nm_flag; |
206 | sbp->f_iosize = uimin(nmp->nm_rsize, nmp->nm_wsize); | | 206 | sbp->f_iosize = uimin(nmp->nm_rsize, nmp->nm_wsize); |
207 | if (v3) { | | 207 | if (v3) { |
208 | sbp->f_frsize = sbp->f_bsize = NFS_FABLKSIZE; | | 208 | sbp->f_frsize = sbp->f_bsize = NFS_FABLKSIZE; |
209 | tquad = fxdr_hyper(&sfp->sf_tbytes); | | 209 | tquad = fxdr_hyper(&sfp->sf_tbytes); |
210 | sbp->f_blocks = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); | | 210 | sbp->f_blocks = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); |
211 | tquad = fxdr_hyper(&sfp->sf_fbytes); | | 211 | tquad = fxdr_hyper(&sfp->sf_fbytes); |
212 | sbp->f_bfree = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); | | 212 | sbp->f_bfree = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); |
213 | tquad = fxdr_hyper(&sfp->sf_abytes); | | 213 | tquad = fxdr_hyper(&sfp->sf_abytes); |
214 | tquad = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); | | 214 | tquad = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); |
215 | sbp->f_bresvd = sbp->f_bfree - tquad; | | 215 | sbp->f_bresvd = sbp->f_bfree - tquad; |
216 | sbp->f_bavail = tquad; | | 216 | sbp->f_bavail = tquad; |
217 | /* Handle older NFS servers returning negative values */ | | 217 | /* Handle older NFS servers returning negative values */ |
218 | if ((quad_t)sbp->f_bavail < 0) | | 218 | if ((quad_t)sbp->f_bavail < 0) |
219 | sbp->f_bavail = 0; | | 219 | sbp->f_bavail = 0; |
220 | tquad = fxdr_hyper(&sfp->sf_tfiles); | | 220 | tquad = fxdr_hyper(&sfp->sf_tfiles); |
221 | sbp->f_files = tquad; | | 221 | sbp->f_files = tquad; |
222 | tquad = fxdr_hyper(&sfp->sf_ffiles); | | 222 | tquad = fxdr_hyper(&sfp->sf_ffiles); |
223 | sbp->f_ffree = tquad; | | 223 | sbp->f_ffree = tquad; |
224 | sbp->f_favail = tquad; | | 224 | sbp->f_favail = tquad; |
225 | sbp->f_fresvd = 0; | | 225 | sbp->f_fresvd = 0; |
226 | sbp->f_namemax = NFS_MAXNAMLEN; | | | |
227 | } else { | | 226 | } else { |
228 | sbp->f_bsize = NFS_FABLKSIZE; | | 227 | sbp->f_bsize = NFS_FABLKSIZE; |
229 | sbp->f_frsize = fxdr_unsigned(int32_t, sfp->sf_bsize); | | 228 | sbp->f_frsize = fxdr_unsigned(int32_t, sfp->sf_bsize); |
230 | sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks); | | 229 | sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks); |
231 | sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree); | | 230 | sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree); |
232 | sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail); | | 231 | sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail); |
233 | sbp->f_fresvd = 0; | | 232 | sbp->f_fresvd = 0; |
234 | sbp->f_files = 0; | | 233 | sbp->f_files = 0; |
235 | sbp->f_ffree = 0; | | 234 | sbp->f_ffree = 0; |
236 | sbp->f_favail = 0; | | 235 | sbp->f_favail = 0; |
237 | sbp->f_fresvd = 0; | | 236 | sbp->f_fresvd = 0; |
238 | sbp->f_namemax = NFS_MAXNAMLEN; | | | |
239 | } | | 237 | } |
240 | copy_statvfs_info(sbp, mp); | | 238 | copy_statvfs_info(sbp, mp); |
241 | nfsm_reqdone; | | 239 | nfsm_reqdone; |
242 | kauth_cred_free(cred); | | 240 | kauth_cred_free(cred); |
243 | return (error); | | 241 | return (error); |
244 | } | | 242 | } |
245 | | | 243 | |
246 | #ifndef NFS_V2_ONLY | | 244 | #ifndef NFS_V2_ONLY |
247 | /* | | 245 | /* |
248 | * nfs version 3 fsinfo rpc call | | 246 | * nfs version 3 fsinfo rpc call |
249 | */ | | 247 | */ |
250 | int | | 248 | int |
251 | nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, kauth_cred_t cred, struct lwp *l) | | 249 | nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, kauth_cred_t cred, struct lwp *l) |
252 | { | | 250 | { |
253 | struct nfsv3_fsinfo *fsp; | | 251 | struct nfsv3_fsinfo *fsp; |
254 | char *cp; | | 252 | char *cp; |
255 | int32_t t1, t2; | | 253 | int32_t t1, t2; |
256 | u_int32_t *tl, pref, xmax; | | 254 | u_int32_t *tl, pref, xmax; |
257 | char *bpos, *dpos, *cp2; | | 255 | char *bpos, *dpos, *cp2; |
258 | int error = 0, retattr; | | 256 | int error = 0, retattr; |
259 | struct mbuf *mreq, *mrep, *md, *mb; | | 257 | struct mbuf *mreq, *mrep, *md, *mb; |
260 | u_int64_t maxfsize; | | 258 | u_int64_t maxfsize; |
261 | struct nfsnode *np = VTONFS(vp); | | 259 | struct nfsnode *np = VTONFS(vp); |
262 | | | 260 | |
263 | nfsstats.rpccnt[NFSPROC_FSINFO]++; | | 261 | nfsstats.rpccnt[NFSPROC_FSINFO]++; |
264 | nfsm_reqhead(np, NFSPROC_FSINFO, NFSX_FH(1)); | | 262 | nfsm_reqhead(np, NFSPROC_FSINFO, NFSX_FH(1)); |
265 | nfsm_fhtom(np, 1); | | 263 | nfsm_fhtom(np, 1); |
266 | nfsm_request(np, NFSPROC_FSINFO, l, cred); | | 264 | nfsm_request(np, NFSPROC_FSINFO, l, cred); |
267 | nfsm_postop_attr(vp, retattr, 0); | | 265 | nfsm_postop_attr(vp, retattr, 0); |
268 | if (!error) { | | 266 | if (!error) { |
269 | nfsm_dissect(fsp, struct nfsv3_fsinfo *, NFSX_V3FSINFO); | | 267 | nfsm_dissect(fsp, struct nfsv3_fsinfo *, NFSX_V3FSINFO); |
270 | pref = fxdr_unsigned(u_int32_t, fsp->fs_wtpref); | | 268 | pref = fxdr_unsigned(u_int32_t, fsp->fs_wtpref); |
271 | if ((nmp->nm_flag & NFSMNT_WSIZE) == 0 && | | 269 | if ((nmp->nm_flag & NFSMNT_WSIZE) == 0 && |
272 | pref < nmp->nm_wsize && pref >= NFS_FABLKSIZE) | | 270 | pref < nmp->nm_wsize && pref >= NFS_FABLKSIZE) |
273 | nmp->nm_wsize = (pref + NFS_FABLKSIZE - 1) & | | 271 | nmp->nm_wsize = (pref + NFS_FABLKSIZE - 1) & |
274 | ~(NFS_FABLKSIZE - 1); | | 272 | ~(NFS_FABLKSIZE - 1); |
275 | xmax = fxdr_unsigned(u_int32_t, fsp->fs_wtmax); | | 273 | xmax = fxdr_unsigned(u_int32_t, fsp->fs_wtmax); |
276 | if (xmax < nmp->nm_wsize && xmax > 0) { | | 274 | if (xmax < nmp->nm_wsize && xmax > 0) { |
277 | nmp->nm_wsize = xmax & ~(NFS_FABLKSIZE - 1); | | 275 | nmp->nm_wsize = xmax & ~(NFS_FABLKSIZE - 1); |
278 | if (nmp->nm_wsize == 0) | | 276 | if (nmp->nm_wsize == 0) |
279 | nmp->nm_wsize = xmax; | | 277 | nmp->nm_wsize = xmax; |
280 | } | | 278 | } |
281 | pref = fxdr_unsigned(u_int32_t, fsp->fs_rtpref); | | 279 | pref = fxdr_unsigned(u_int32_t, fsp->fs_rtpref); |
282 | if ((nmp->nm_flag & NFSMNT_RSIZE) == 0 && | | 280 | if ((nmp->nm_flag & NFSMNT_RSIZE) == 0 && |
283 | pref < nmp->nm_rsize && pref >= NFS_FABLKSIZE) | | 281 | pref < nmp->nm_rsize && pref >= NFS_FABLKSIZE) |
284 | nmp->nm_rsize = (pref + NFS_FABLKSIZE - 1) & | | 282 | nmp->nm_rsize = (pref + NFS_FABLKSIZE - 1) & |
285 | ~(NFS_FABLKSIZE - 1); | | 283 | ~(NFS_FABLKSIZE - 1); |
286 | xmax = fxdr_unsigned(u_int32_t, fsp->fs_rtmax); | | 284 | xmax = fxdr_unsigned(u_int32_t, fsp->fs_rtmax); |
287 | if (xmax < nmp->nm_rsize && xmax > 0) { | | 285 | if (xmax < nmp->nm_rsize && xmax > 0) { |
288 | nmp->nm_rsize = xmax & ~(NFS_FABLKSIZE - 1); | | 286 | nmp->nm_rsize = xmax & ~(NFS_FABLKSIZE - 1); |
289 | if (nmp->nm_rsize == 0) | | 287 | if (nmp->nm_rsize == 0) |
290 | nmp->nm_rsize = xmax; | | 288 | nmp->nm_rsize = xmax; |
291 | } | | 289 | } |
292 | pref = fxdr_unsigned(u_int32_t, fsp->fs_dtpref); | | 290 | pref = fxdr_unsigned(u_int32_t, fsp->fs_dtpref); |
293 | if (pref < nmp->nm_readdirsize && pref >= NFS_DIRFRAGSIZ) | | 291 | if (pref < nmp->nm_readdirsize && pref >= NFS_DIRFRAGSIZ) |
294 | nmp->nm_readdirsize = (pref + NFS_DIRFRAGSIZ - 1) & | | 292 | nmp->nm_readdirsize = (pref + NFS_DIRFRAGSIZ - 1) & |
295 | ~(NFS_DIRFRAGSIZ - 1); | | 293 | ~(NFS_DIRFRAGSIZ - 1); |
296 | if (xmax < nmp->nm_readdirsize && xmax > 0) { | | 294 | if (xmax < nmp->nm_readdirsize && xmax > 0) { |
297 | nmp->nm_readdirsize = xmax & ~(NFS_DIRFRAGSIZ - 1); | | 295 | nmp->nm_readdirsize = xmax & ~(NFS_DIRFRAGSIZ - 1); |
298 | if (nmp->nm_readdirsize == 0) | | 296 | if (nmp->nm_readdirsize == 0) |
299 | nmp->nm_readdirsize = xmax; | | 297 | nmp->nm_readdirsize = xmax; |
300 | } | | 298 | } |
301 | /* XXX */ | | 299 | /* XXX */ |
302 | nmp->nm_maxfilesize = (u_int64_t)0x80000000 * DEV_BSIZE - 1; | | 300 | nmp->nm_maxfilesize = (u_int64_t)0x80000000 * DEV_BSIZE - 1; |
303 | maxfsize = fxdr_hyper(&fsp->fs_maxfilesize); | | 301 | maxfsize = fxdr_hyper(&fsp->fs_maxfilesize); |
304 | if (maxfsize > 0 && maxfsize < nmp->nm_maxfilesize) | | 302 | if (maxfsize > 0 && maxfsize < nmp->nm_maxfilesize) |
305 | nmp->nm_maxfilesize = maxfsize; | | 303 | nmp->nm_maxfilesize = maxfsize; |
306 | nmp->nm_mountp->mnt_fs_bshift = | | 304 | nmp->nm_mountp->mnt_fs_bshift = |
307 | ffs(MIN(nmp->nm_rsize, nmp->nm_wsize)) - 1; | | 305 | ffs(MIN(nmp->nm_rsize, nmp->nm_wsize)) - 1; |
308 | nmp->nm_iflag |= NFSMNT_GOTFSINFO; | | 306 | nmp->nm_iflag |= NFSMNT_GOTFSINFO; |
309 | } | | 307 | } |
310 | nfsm_reqdone; | | 308 | nfsm_reqdone; |
311 | return (error); | | 309 | return (error); |
312 | } | | 310 | } |
313 | #endif | | 311 | #endif |
314 | | | 312 | |
315 | /* | | 313 | /* |
316 | * Mount a remote root fs via. NFS. It goes like this: | | 314 | * Mount a remote root fs via. NFS. It goes like this: |
317 | * - Call nfs_boot_init() to fill in the nfs_diskless struct | | 315 | * - Call nfs_boot_init() to fill in the nfs_diskless struct |
318 | * - build the rootfs mount point and call mountnfs() to do the rest. | | 316 | * - build the rootfs mount point and call mountnfs() to do the rest. |
319 | */ | | 317 | */ |
320 | int | | 318 | int |
321 | nfs_mountroot(void) | | 319 | nfs_mountroot(void) |
322 | { | | 320 | { |
323 | struct timespec ts; | | 321 | struct timespec ts; |
324 | struct nfs_diskless *nd; | | 322 | struct nfs_diskless *nd; |
325 | struct vattr attr; | | 323 | struct vattr attr; |
326 | struct mount *mp; | | 324 | struct mount *mp; |
327 | struct vnode *vp; | | 325 | struct vnode *vp; |
328 | struct lwp *l; | | 326 | struct lwp *l; |
329 | long n; | | 327 | long n; |
330 | int error; | | 328 | int error; |
331 | | | 329 | |
332 | l = curlwp; /* XXX */ | | 330 | l = curlwp; /* XXX */ |
333 | | | 331 | |
334 | if (device_class(root_device) != DV_IFNET) | | 332 | if (device_class(root_device) != DV_IFNET) |
335 | return (ENODEV); | | 333 | return (ENODEV); |
336 | | | 334 | |
337 | /* | | 335 | /* |
338 | * XXX time must be non-zero when we init the interface or else | | 336 | * XXX time must be non-zero when we init the interface or else |
339 | * the arp code will wedge. [Fixed now in if_ether.c] | | 337 | * the arp code will wedge. [Fixed now in if_ether.c] |
340 | * However, the NFS attribute cache gives false "hits" when the | | 338 | * However, the NFS attribute cache gives false "hits" when the |
341 | * current time < nfs_attrtimeo(nmp, np) so keep this in for now. | | 339 | * current time < nfs_attrtimeo(nmp, np) so keep this in for now. |
342 | */ | | 340 | */ |
343 | if (time_second < NFS_MAXATTRTIMO) { | | 341 | if (time_second < NFS_MAXATTRTIMO) { |
344 | ts.tv_sec = NFS_MAXATTRTIMO; | | 342 | ts.tv_sec = NFS_MAXATTRTIMO; |
345 | ts.tv_nsec = 0; | | 343 | ts.tv_nsec = 0; |
346 | tc_setclock(&ts); | | 344 | tc_setclock(&ts); |
347 | } | | 345 | } |
348 | | | 346 | |
349 | /* | | 347 | /* |
350 | * Call nfs_boot_init() to fill in the nfs_diskless struct. | | 348 | * Call nfs_boot_init() to fill in the nfs_diskless struct. |
351 | * Side effect: Finds and configures a network interface. | | 349 | * Side effect: Finds and configures a network interface. |
352 | */ | | 350 | */ |
353 | nd = kmem_zalloc(sizeof(*nd), KM_SLEEP); | | 351 | nd = kmem_zalloc(sizeof(*nd), KM_SLEEP); |
354 | error = nfs_boot_init(nd, l); | | 352 | error = nfs_boot_init(nd, l); |
355 | if (error) { | | 353 | if (error) { |
356 | kmem_free(nd, sizeof(*nd)); | | 354 | kmem_free(nd, sizeof(*nd)); |
357 | return (error); | | 355 | return (error); |
358 | } | | 356 | } |
359 | | | 357 | |
360 | /* | | 358 | /* |
361 | * Create the root mount point. | | 359 | * Create the root mount point. |
362 | */ | | 360 | */ |
363 | error = nfs_mount_diskless(&nd->nd_root, "/", &mp, &vp, l); | | 361 | error = nfs_mount_diskless(&nd->nd_root, "/", &mp, &vp, l); |
364 | if (error) | | 362 | if (error) |
365 | goto out; | | 363 | goto out; |
366 | printf("root on %s\n", nd->nd_root.ndm_host); | | 364 | printf("root on %s\n", nd->nd_root.ndm_host); |
367 | | | 365 | |
368 | /* | | 366 | /* |
369 | * Link it into the mount list. | | 367 | * Link it into the mount list. |
370 | */ | | 368 | */ |
371 | mountlist_append(mp); | | 369 | mountlist_append(mp); |
372 | rootvp = vp; | | 370 | rootvp = vp; |
373 | mp->mnt_vnodecovered = NULLVP; | | 371 | mp->mnt_vnodecovered = NULLVP; |
374 | vfs_unbusy(mp); | | 372 | vfs_unbusy(mp); |
375 | | | 373 | |
376 | /* Get root attributes (for the time). */ | | 374 | /* Get root attributes (for the time). */ |
377 | vn_lock(vp, LK_SHARED | LK_RETRY); | | 375 | vn_lock(vp, LK_SHARED | LK_RETRY); |
378 | error = VOP_GETATTR(vp, &attr, l->l_cred); | | 376 | error = VOP_GETATTR(vp, &attr, l->l_cred); |
379 | VOP_UNLOCK(vp); | | 377 | VOP_UNLOCK(vp); |
380 | if (error) | | 378 | if (error) |
381 | panic("nfs_mountroot: getattr for root"); | | 379 | panic("nfs_mountroot: getattr for root"); |
382 | n = attr.va_atime.tv_sec; | | 380 | n = attr.va_atime.tv_sec; |
383 | #ifdef DEBUG | | 381 | #ifdef DEBUG |
384 | printf("root time: 0x%lx\n", n); | | 382 | printf("root time: 0x%lx\n", n); |
385 | #endif | | 383 | #endif |
386 | setrootfstime(n); | | 384 | setrootfstime(n); |
387 | | | 385 | |
388 | out: | | 386 | out: |
389 | if (error) | | 387 | if (error) |
390 | nfs_boot_cleanup(nd, l); | | 388 | nfs_boot_cleanup(nd, l); |
391 | kmem_free(nd, sizeof(*nd)); | | 389 | kmem_free(nd, sizeof(*nd)); |
392 | return (error); | | 390 | return (error); |
393 | } | | 391 | } |
394 | | | 392 | |
395 | /* | | 393 | /* |
396 | * Internal version of mount system call for diskless setup. | | 394 | * Internal version of mount system call for diskless setup. |
397 | * Separate function because we used to call it twice. | | 395 | * Separate function because we used to call it twice. |
398 | * (once for root and once for swap) | | 396 | * (once for root and once for swap) |
399 | */ | | 397 | */ |
400 | static int | | 398 | static int |
401 | nfs_mount_diskless(struct nfs_dlmount *ndmntp, const char *mntname, struct mount **mpp, struct vnode **vpp, struct lwp *l) | | 399 | nfs_mount_diskless(struct nfs_dlmount *ndmntp, const char *mntname, struct mount **mpp, struct vnode **vpp, struct lwp *l) |
402 | /* mntname: mount point name */ | | 400 | /* mntname: mount point name */ |
403 | { | | 401 | { |
404 | struct mount *mp; | | 402 | struct mount *mp; |
405 | struct mbuf *m; | | 403 | struct mbuf *m; |
406 | int error; | | 404 | int error; |
407 | | | 405 | |
408 | vfs_rootmountalloc(MOUNT_NFS, mntname, &mp); | | 406 | vfs_rootmountalloc(MOUNT_NFS, mntname, &mp); |
409 | | | 407 | |
410 | mp->mnt_op = &nfs_vfsops; | | 408 | mp->mnt_op = &nfs_vfsops; |
411 | | | 409 | |
412 | /* | | 410 | /* |
413 | * Historical practice expects NFS root file systems to | | 411 | * Historical practice expects NFS root file systems to |
414 | * be initially mounted r/w. | | 412 | * be initially mounted r/w. |
415 | */ | | 413 | */ |
416 | mp->mnt_flag &= ~MNT_RDONLY; | | 414 | mp->mnt_flag &= ~MNT_RDONLY; |
417 | | | 415 | |
418 | /* Get mbuf for server sockaddr. */ | | 416 | /* Get mbuf for server sockaddr. */ |
419 | m = m_get(M_WAIT, MT_SONAME); | | 417 | m = m_get(M_WAIT, MT_SONAME); |
420 | if (m == NULL) | | 418 | if (m == NULL) |
421 | panic("nfs_mountroot: mget soname for %s", mntname); | | 419 | panic("nfs_mountroot: mget soname for %s", mntname); |
422 | MCLAIM(m, &nfs_mowner); | | 420 | MCLAIM(m, &nfs_mowner); |
423 | memcpy(mtod(m, void *), (void *)ndmntp->ndm_args.addr, | | 421 | memcpy(mtod(m, void *), (void *)ndmntp->ndm_args.addr, |
424 | (m->m_len = ndmntp->ndm_args.addr->sa_len)); | | 422 | (m->m_len = ndmntp->ndm_args.addr->sa_len)); |
425 | | | 423 | |
426 | error = mountnfs(&ndmntp->ndm_args, mp, m, mntname, | | 424 | error = mountnfs(&ndmntp->ndm_args, mp, m, mntname, |
427 | ndmntp->ndm_args.hostname, vpp, l); | | 425 | ndmntp->ndm_args.hostname, vpp, l); |
428 | if (error) { | | 426 | if (error) { |
429 | vfs_unbusy(mp); | | 427 | vfs_unbusy(mp); |
430 | vfs_rele(mp); | | 428 | vfs_rele(mp); |
431 | printf("nfs_mountroot: mount %s failed: %d\n", | | 429 | printf("nfs_mountroot: mount %s failed: %d\n", |
432 | mntname, error); | | 430 | mntname, error); |
433 | } else | | 431 | } else |
434 | *mpp = mp; | | 432 | *mpp = mp; |
435 | | | 433 | |
436 | return (error); | | 434 | return (error); |
437 | } | | 435 | } |
438 | | | 436 | |
439 | void | | 437 | void |
440 | nfs_decode_args(struct nfsmount *nmp, struct nfs_args *argp, struct lwp *l) | | 438 | nfs_decode_args(struct nfsmount *nmp, struct nfs_args *argp, struct lwp *l) |
441 | { | | 439 | { |
442 | int s; | | 440 | int s; |
443 | int adjsock; | | 441 | int adjsock; |
444 | int maxio; | | 442 | int maxio; |
445 | | | 443 | |
446 | s = splsoftnet(); | | 444 | s = splsoftnet(); |
447 | | | 445 | |
448 | /* | | 446 | /* |
449 | * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes | | 447 | * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes |
450 | * no sense in that context. | | 448 | * no sense in that context. |
451 | */ | | 449 | */ |
452 | if (argp->sotype == SOCK_STREAM) | | 450 | if (argp->sotype == SOCK_STREAM) |
453 | argp->flags &= ~NFSMNT_NOCONN; | | 451 | argp->flags &= ~NFSMNT_NOCONN; |
454 | | | 452 | |
455 | /* | | 453 | /* |
456 | * Cookie translation is not needed for v2, silently ignore it. | | 454 | * Cookie translation is not needed for v2, silently ignore it. |
457 | */ | | 455 | */ |
458 | if ((argp->flags & (NFSMNT_XLATECOOKIE|NFSMNT_NFSV3)) == | | 456 | if ((argp->flags & (NFSMNT_XLATECOOKIE|NFSMNT_NFSV3)) == |
459 | NFSMNT_XLATECOOKIE) | | 457 | NFSMNT_XLATECOOKIE) |
460 | argp->flags &= ~NFSMNT_XLATECOOKIE; | | 458 | argp->flags &= ~NFSMNT_XLATECOOKIE; |
461 | | | 459 | |
462 | /* Re-bind if rsrvd port requested and wasn't on one */ | | 460 | /* Re-bind if rsrvd port requested and wasn't on one */ |
463 | adjsock = !(nmp->nm_flag & NFSMNT_RESVPORT) | | 461 | adjsock = !(nmp->nm_flag & NFSMNT_RESVPORT) |
464 | && (argp->flags & NFSMNT_RESVPORT); | | 462 | && (argp->flags & NFSMNT_RESVPORT); |
465 | /* Also re-bind if we're switching to/from a connected UDP socket */ | | 463 | /* Also re-bind if we're switching to/from a connected UDP socket */ |
466 | adjsock |= ((nmp->nm_flag & NFSMNT_NOCONN) != | | 464 | adjsock |= ((nmp->nm_flag & NFSMNT_NOCONN) != |
467 | (argp->flags & NFSMNT_NOCONN)); | | 465 | (argp->flags & NFSMNT_NOCONN)); |
468 | | | 466 | |
469 | /* Update flags. */ | | 467 | /* Update flags. */ |
470 | nmp->nm_flag = argp->flags; | | 468 | nmp->nm_flag = argp->flags; |
471 | splx(s); | | 469 | splx(s); |
472 | | | 470 | |
473 | if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) { | | 471 | if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) { |
474 | nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10; | | 472 | nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10; |
475 | if (nmp->nm_timeo < NFS_MINTIMEO) | | 473 | if (nmp->nm_timeo < NFS_MINTIMEO) |
476 | nmp->nm_timeo = NFS_MINTIMEO; | | 474 | nmp->nm_timeo = NFS_MINTIMEO; |
477 | else if (nmp->nm_timeo > NFS_MAXTIMEO) | | 475 | else if (nmp->nm_timeo > NFS_MAXTIMEO) |
478 | nmp->nm_timeo = NFS_MAXTIMEO; | | 476 | nmp->nm_timeo = NFS_MAXTIMEO; |
479 | } | | 477 | } |
480 | | | 478 | |
481 | if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) { | | 479 | if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) { |
482 | nmp->nm_retry = argp->retrans; | | 480 | nmp->nm_retry = argp->retrans; |
483 | if (nmp->nm_retry > NFS_MAXREXMIT) | | 481 | if (nmp->nm_retry > NFS_MAXREXMIT) |
484 | nmp->nm_retry = NFS_MAXREXMIT; | | 482 | nmp->nm_retry = NFS_MAXREXMIT; |
485 | } | | 483 | } |
486 | | | 484 | |
487 | #ifndef NFS_V2_ONLY | | 485 | #ifndef NFS_V2_ONLY |
488 | if (argp->flags & NFSMNT_NFSV3) { | | 486 | if (argp->flags & NFSMNT_NFSV3) { |
489 | if (argp->sotype == SOCK_DGRAM) | | 487 | if (argp->sotype == SOCK_DGRAM) |
490 | maxio = NFS_MAXDGRAMDATA; | | 488 | maxio = NFS_MAXDGRAMDATA; |
491 | else | | 489 | else |
492 | maxio = NFS_MAXDATA; | | 490 | maxio = NFS_MAXDATA; |
493 | } else | | 491 | } else |
494 | #endif | | 492 | #endif |
495 | maxio = NFS_V2MAXDATA; | | 493 | maxio = NFS_V2MAXDATA; |
496 | | | 494 | |
497 | if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) { | | 495 | if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) { |
498 | int osize = nmp->nm_wsize; | | 496 | int osize = nmp->nm_wsize; |
499 | nmp->nm_wsize = argp->wsize; | | 497 | nmp->nm_wsize = argp->wsize; |
500 | /* Round down to multiple of blocksize */ | | 498 | /* Round down to multiple of blocksize */ |
501 | nmp->nm_wsize &= ~(NFS_FABLKSIZE - 1); | | 499 | nmp->nm_wsize &= ~(NFS_FABLKSIZE - 1); |
502 | if (nmp->nm_wsize <= 0) | | 500 | if (nmp->nm_wsize <= 0) |
503 | nmp->nm_wsize = NFS_FABLKSIZE; | | 501 | nmp->nm_wsize = NFS_FABLKSIZE; |
504 | adjsock |= (nmp->nm_wsize != osize); | | 502 | adjsock |= (nmp->nm_wsize != osize); |
505 | } | | 503 | } |
506 | if (nmp->nm_wsize > maxio) | | 504 | if (nmp->nm_wsize > maxio) |
507 | nmp->nm_wsize = maxio; | | 505 | nmp->nm_wsize = maxio; |
508 | if (nmp->nm_wsize > MAXBSIZE) | | 506 | if (nmp->nm_wsize > MAXBSIZE) |
509 | nmp->nm_wsize = MAXBSIZE; | | 507 | nmp->nm_wsize = MAXBSIZE; |
510 | | | 508 | |
511 | if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) { | | 509 | if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) { |
512 | int osize = nmp->nm_rsize; | | 510 | int osize = nmp->nm_rsize; |
513 | nmp->nm_rsize = argp->rsize; | | 511 | nmp->nm_rsize = argp->rsize; |
514 | /* Round down to multiple of blocksize */ | | 512 | /* Round down to multiple of blocksize */ |
515 | nmp->nm_rsize &= ~(NFS_FABLKSIZE - 1); | | 513 | nmp->nm_rsize &= ~(NFS_FABLKSIZE - 1); |
516 | if (nmp->nm_rsize <= 0) | | 514 | if (nmp->nm_rsize <= 0) |
517 | nmp->nm_rsize = NFS_FABLKSIZE; | | 515 | nmp->nm_rsize = NFS_FABLKSIZE; |
518 | adjsock |= (nmp->nm_rsize != osize); | | 516 | adjsock |= (nmp->nm_rsize != osize); |
519 | } | | 517 | } |
520 | if (nmp->nm_rsize > maxio) | | 518 | if (nmp->nm_rsize > maxio) |
521 | nmp->nm_rsize = maxio; | | 519 | nmp->nm_rsize = maxio; |
522 | if (nmp->nm_rsize > MAXBSIZE) | | 520 | if (nmp->nm_rsize > MAXBSIZE) |
523 | nmp->nm_rsize = MAXBSIZE; | | 521 | nmp->nm_rsize = MAXBSIZE; |
524 | | | 522 | |
525 | if ((argp->flags & NFSMNT_READDIRSIZE) && argp->readdirsize > 0) { | | 523 | if ((argp->flags & NFSMNT_READDIRSIZE) && argp->readdirsize > 0) { |
526 | nmp->nm_readdirsize = argp->readdirsize; | | 524 | nmp->nm_readdirsize = argp->readdirsize; |
527 | /* Round down to multiple of minimum blocksize */ | | 525 | /* Round down to multiple of minimum blocksize */ |
528 | nmp->nm_readdirsize &= ~(NFS_DIRFRAGSIZ - 1); | | 526 | nmp->nm_readdirsize &= ~(NFS_DIRFRAGSIZ - 1); |
529 | if (nmp->nm_readdirsize < NFS_DIRFRAGSIZ) | | 527 | if (nmp->nm_readdirsize < NFS_DIRFRAGSIZ) |
530 | nmp->nm_readdirsize = NFS_DIRFRAGSIZ; | | 528 | nmp->nm_readdirsize = NFS_DIRFRAGSIZ; |
531 | /* Bigger than buffer size makes no sense */ | | 529 | /* Bigger than buffer size makes no sense */ |
532 | if (nmp->nm_readdirsize > NFS_DIRBLKSIZ) | | 530 | if (nmp->nm_readdirsize > NFS_DIRBLKSIZ) |
533 | nmp->nm_readdirsize = NFS_DIRBLKSIZ; | | 531 | nmp->nm_readdirsize = NFS_DIRBLKSIZ; |
534 | } else if (argp->flags & NFSMNT_RSIZE) | | 532 | } else if (argp->flags & NFSMNT_RSIZE) |
535 | nmp->nm_readdirsize = nmp->nm_rsize; | | 533 | nmp->nm_readdirsize = nmp->nm_rsize; |
536 | | | 534 | |
537 | if (nmp->nm_readdirsize > maxio) | | 535 | if (nmp->nm_readdirsize > maxio) |
538 | nmp->nm_readdirsize = maxio; | | 536 | nmp->nm_readdirsize = maxio; |
539 | | | 537 | |
540 | if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 && | | 538 | if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 && |
541 | argp->maxgrouplist <= NFS_MAXGRPS) | | 539 | argp->maxgrouplist <= NFS_MAXGRPS) |
542 | nmp->nm_numgrps = argp->maxgrouplist; | | 540 | nmp->nm_numgrps = argp->maxgrouplist; |
543 | if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 && | | 541 | if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 && |
544 | argp->readahead <= NFS_MAXRAHEAD) | | 542 | argp->readahead <= NFS_MAXRAHEAD) |
545 | nmp->nm_readahead = argp->readahead; | | 543 | nmp->nm_readahead = argp->readahead; |
546 | if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 && | | 544 | if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 && |
547 | argp->deadthresh <= NFS_NEVERDEAD) | | 545 | argp->deadthresh <= NFS_NEVERDEAD) |
548 | nmp->nm_deadthresh = argp->deadthresh; | | 546 | nmp->nm_deadthresh = argp->deadthresh; |
549 | | | 547 | |
550 | adjsock |= ((nmp->nm_sotype != argp->sotype) || | | 548 | adjsock |= ((nmp->nm_sotype != argp->sotype) || |
551 | (nmp->nm_soproto != argp->proto)); | | 549 | (nmp->nm_soproto != argp->proto)); |
552 | nmp->nm_sotype = argp->sotype; | | 550 | nmp->nm_sotype = argp->sotype; |
553 | nmp->nm_soproto = argp->proto; | | 551 | nmp->nm_soproto = argp->proto; |
554 | | | 552 | |
555 | if (nmp->nm_so && adjsock) { | | 553 | if (nmp->nm_so && adjsock) { |
556 | nfs_safedisconnect(nmp); | | 554 | nfs_safedisconnect(nmp); |
557 | if (nmp->nm_sotype == SOCK_DGRAM) | | 555 | if (nmp->nm_sotype == SOCK_DGRAM) |
558 | while (nfs_connect(nmp, (struct nfsreq *)0, l)) { | | 556 | while (nfs_connect(nmp, (struct nfsreq *)0, l)) { |
559 | printf("nfs_args: retrying connect\n"); | | 557 | printf("nfs_args: retrying connect\n"); |
560 | kpause("nfscn3", false, hz, NULL); | | 558 | kpause("nfscn3", false, hz, NULL); |
561 | } | | 559 | } |
562 | } | | 560 | } |
563 | } | | 561 | } |
564 | | | 562 | |
565 | /* | | 563 | /* |
566 | * VFS Operations. | | 564 | * VFS Operations. |
567 | * | | 565 | * |
568 | * mount system call | | 566 | * mount system call |
569 | * It seems a bit dumb to copyinstr() the host and path here and then | | 567 | * It seems a bit dumb to copyinstr() the host and path here and then |
570 | * memcpy() them in mountnfs(), but I wanted to detect errors before | | 568 | * memcpy() them in mountnfs(), but I wanted to detect errors before |
571 | * doing the sockargs() call because sockargs() allocates an mbuf and | | 569 | * doing the sockargs() call because sockargs() allocates an mbuf and |
572 | * an error after that means that I have to release the mbuf. | | 570 | * an error after that means that I have to release the mbuf. |
573 | */ | | 571 | */ |
574 | /* ARGSUSED */ | | 572 | /* ARGSUSED */ |
575 | int | | 573 | int |
576 | nfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) | | 574 | nfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) |
577 | { | | 575 | { |
578 | struct lwp *l = curlwp; | | 576 | struct lwp *l = curlwp; |
579 | int error; | | 577 | int error; |
580 | struct nfs_args *args = data; | | 578 | struct nfs_args *args = data; |
581 | struct mbuf *nam; | | 579 | struct mbuf *nam; |
582 | struct nfsmount *nmp = VFSTONFS(mp); | | 580 | struct nfsmount *nmp = VFSTONFS(mp); |
583 | struct sockaddr *sa; | | 581 | struct sockaddr *sa; |
584 | struct vnode *vp; | | 582 | struct vnode *vp; |
585 | char *pth, *hst; | | 583 | char *pth, *hst; |
586 | size_t len; | | 584 | size_t len; |
587 | u_char *nfh; | | 585 | u_char *nfh; |
588 | | | 586 | |
589 | if (args == NULL) | | 587 | if (args == NULL) |
590 | return EINVAL; | | 588 | return EINVAL; |
591 | if (*data_len < sizeof *args) | | 589 | if (*data_len < sizeof *args) |
592 | return EINVAL; | | 590 | return EINVAL; |
593 | | | 591 | |
594 | if (mp->mnt_flag & MNT_GETARGS) { | | 592 | if (mp->mnt_flag & MNT_GETARGS) { |
595 | | | 593 | |
596 | if (nmp == NULL) | | 594 | if (nmp == NULL) |
597 | return (EIO); | | 595 | return (EIO); |
598 | if (args->addr != NULL) { | | 596 | if (args->addr != NULL) { |
599 | sa = mtod(nmp->nm_nam, struct sockaddr *); | | 597 | sa = mtod(nmp->nm_nam, struct sockaddr *); |
600 | error = copyout(sa, args->addr, sa->sa_len); | | 598 | error = copyout(sa, args->addr, sa->sa_len); |
601 | if (error) | | 599 | if (error) |
602 | return (error); | | 600 | return (error); |
603 | args->addrlen = sa->sa_len; | | 601 | args->addrlen = sa->sa_len; |
604 | } else | | 602 | } else |
605 | args->addrlen = 0; | | 603 | args->addrlen = 0; |
606 | | | 604 | |
607 | args->version = NFS_ARGSVERSION; | | 605 | args->version = NFS_ARGSVERSION; |
608 | args->sotype = nmp->nm_sotype; | | 606 | args->sotype = nmp->nm_sotype; |
609 | args->proto = nmp->nm_soproto; | | 607 | args->proto = nmp->nm_soproto; |
610 | args->fh = NULL; | | 608 | args->fh = NULL; |
611 | args->fhsize = 0; | | 609 | args->fhsize = 0; |
612 | args->flags = nmp->nm_flag; | | 610 | args->flags = nmp->nm_flag; |
613 | args->wsize = nmp->nm_wsize; | | 611 | args->wsize = nmp->nm_wsize; |
614 | args->rsize = nmp->nm_rsize; | | 612 | args->rsize = nmp->nm_rsize; |
615 | args->readdirsize = nmp->nm_readdirsize; | | 613 | args->readdirsize = nmp->nm_readdirsize; |
616 | args->timeo = nmp->nm_timeo; | | 614 | args->timeo = nmp->nm_timeo; |
617 | args->retrans = nmp->nm_retry; | | 615 | args->retrans = nmp->nm_retry; |
618 | args->maxgrouplist = nmp->nm_numgrps; | | 616 | args->maxgrouplist = nmp->nm_numgrps; |
619 | args->readahead = nmp->nm_readahead; | | 617 | args->readahead = nmp->nm_readahead; |
620 | args->leaseterm = 0; /* dummy */ | | 618 | args->leaseterm = 0; /* dummy */ |
621 | args->deadthresh = nmp->nm_deadthresh; | | 619 | args->deadthresh = nmp->nm_deadthresh; |
622 | args->hostname = NULL; | | 620 | args->hostname = NULL; |
623 | *data_len = sizeof *args; | | 621 | *data_len = sizeof *args; |
624 | return 0; | | 622 | return 0; |
625 | } | | 623 | } |
626 | | | 624 | |
627 | if (args->version != NFS_ARGSVERSION) | | 625 | if (args->version != NFS_ARGSVERSION) |
628 | return (EPROGMISMATCH); | | 626 | return (EPROGMISMATCH); |
629 | if (args->flags & (NFSMNT_NQNFS|NFSMNT_KERB)) | | 627 | if (args->flags & (NFSMNT_NQNFS|NFSMNT_KERB)) |
630 | return (EPROGUNAVAIL); | | 628 | return (EPROGUNAVAIL); |
631 | #ifdef NFS_V2_ONLY | | 629 | #ifdef NFS_V2_ONLY |
632 | if (args->flags & NFSMNT_NFSV3) | | 630 | if (args->flags & NFSMNT_NFSV3) |
633 | return (EPROGMISMATCH); | | 631 | return (EPROGMISMATCH); |
634 | #endif | | 632 | #endif |
635 | if (mp->mnt_flag & MNT_UPDATE) { | | 633 | if (mp->mnt_flag & MNT_UPDATE) { |
636 | if (nmp == NULL) | | 634 | if (nmp == NULL) |
637 | return (EIO); | | 635 | return (EIO); |
638 | /* | | 636 | /* |
639 | * When doing an update, we can't change from or to | | 637 | * When doing an update, we can't change from or to |
640 | * v3, or change cookie translation | | 638 | * v3, or change cookie translation |
641 | */ | | 639 | */ |
642 | args->flags = (args->flags & ~(NFSMNT_NFSV3|NFSMNT_XLATECOOKIE)) | | | 640 | args->flags = (args->flags & ~(NFSMNT_NFSV3|NFSMNT_XLATECOOKIE)) | |
643 | (nmp->nm_flag & (NFSMNT_NFSV3|NFSMNT_XLATECOOKIE)); | | 641 | (nmp->nm_flag & (NFSMNT_NFSV3|NFSMNT_XLATECOOKIE)); |
644 | nfs_decode_args(nmp, args, l); | | 642 | nfs_decode_args(nmp, args, l); |
645 | return (0); | | 643 | return (0); |
646 | } | | 644 | } |
647 | if (args->fhsize < 0 || args->fhsize > NFSX_V3FHMAX) | | 645 | if (args->fhsize < 0 || args->fhsize > NFSX_V3FHMAX) |
648 | return (EINVAL); | | 646 | return (EINVAL); |
649 | nfh = malloc(NFSX_V3FHMAX, M_TEMP, M_WAITOK); | | 647 | nfh = malloc(NFSX_V3FHMAX, M_TEMP, M_WAITOK); |
650 | error = copyin(args->fh, nfh, args->fhsize); | | 648 | error = copyin(args->fh, nfh, args->fhsize); |
651 | if (error) | | 649 | if (error) |
652 | goto free_nfh; | | 650 | goto free_nfh; |
653 | pth = malloc(MNAMELEN, M_TEMP, M_WAITOK); | | 651 | pth = malloc(MNAMELEN, M_TEMP, M_WAITOK); |
654 | error = copyinstr(path, pth, MNAMELEN - 1, &len); | | 652 | error = copyinstr(path, pth, MNAMELEN - 1, &len); |
655 | if (error) | | 653 | if (error) |
656 | goto free_pth; | | 654 | goto free_pth; |
657 | memset(&pth[len], 0, MNAMELEN - len); | | 655 | memset(&pth[len], 0, MNAMELEN - len); |
658 | hst = malloc(MNAMELEN, M_TEMP, M_WAITOK); | | 656 | hst = malloc(MNAMELEN, M_TEMP, M_WAITOK); |
659 | error = copyinstr(args->hostname, hst, MNAMELEN - 1, &len); | | 657 | error = copyinstr(args->hostname, hst, MNAMELEN - 1, &len); |
660 | if (error) | | 658 | if (error) |
661 | goto free_hst; | | 659 | goto free_hst; |
662 | memset(&hst[len], 0, MNAMELEN - len); | | 660 | memset(&hst[len], 0, MNAMELEN - len); |
663 | /* sockargs() call must be after above copyin() calls */ | | 661 | /* sockargs() call must be after above copyin() calls */ |
664 | error = sockargs(&nam, args->addr, args->addrlen, UIO_USERSPACE, | | 662 | error = sockargs(&nam, args->addr, args->addrlen, UIO_USERSPACE, |
665 | MT_SONAME); | | 663 | MT_SONAME); |
666 | if (error) | | 664 | if (error) |
667 | goto free_hst; | | 665 | goto free_hst; |
668 | MCLAIM(nam, &nfs_mowner); | | 666 | MCLAIM(nam, &nfs_mowner); |
669 | args->fh = nfh; | | 667 | args->fh = nfh; |
670 | error = mountnfs(args, mp, nam, pth, hst, &vp, l); | | 668 | error = mountnfs(args, mp, nam, pth, hst, &vp, l); |
671 | | | 669 | |
672 | free_hst: | | 670 | free_hst: |
673 | free(hst, M_TEMP); | | 671 | free(hst, M_TEMP); |
674 | free_pth: | | 672 | free_pth: |
675 | free(pth, M_TEMP); | | 673 | free(pth, M_TEMP); |
676 | free_nfh: | | 674 | free_nfh: |
677 | free(nfh, M_TEMP); | | 675 | free(nfh, M_TEMP); |
678 | | | 676 | |
679 | return (error); | | 677 | return (error); |
680 | } | | 678 | } |
681 | | | 679 | |
682 | /* | | 680 | /* |
683 | * Common code for mount and mountroot | | 681 | * Common code for mount and mountroot |
684 | */ | | 682 | */ |
685 | int | | 683 | int |
686 | mountnfs(struct nfs_args *argp, struct mount *mp, struct mbuf *nam, const char *pth, const char *hst, struct vnode **vpp, struct lwp *l) | | 684 | mountnfs(struct nfs_args *argp, struct mount *mp, struct mbuf *nam, const char *pth, const char *hst, struct vnode **vpp, struct lwp *l) |
687 | { | | 685 | { |
688 | struct nfsmount *nmp; | | 686 | struct nfsmount *nmp; |
689 | struct nfsnode *np; | | 687 | struct nfsnode *np; |
690 | struct vnode *vp; | | 688 | struct vnode *vp; |
691 | int error; | | 689 | int error; |
692 | struct vattr *attrs; | | 690 | struct vattr *attrs; |
693 | kauth_cred_t cr; | | 691 | kauth_cred_t cr; |
694 | char iosname[IOSTATNAMELEN]; | | 692 | char iosname[IOSTATNAMELEN]; |
695 | | | 693 | |
696 | /* | | 694 | /* |
697 | * If the number of nfs iothreads to use has never | | 695 | * If the number of nfs iothreads to use has never |
698 | * been set, create a reasonable number of them. | | 696 | * been set, create a reasonable number of them. |
699 | */ | | 697 | */ |
700 | | | 698 | |
701 | if (nfs_niothreads < 0) { | | 699 | if (nfs_niothreads < 0) { |
702 | nfs_set_niothreads(NFS_DEFAULT_NIOTHREADS); | | 700 | nfs_set_niothreads(NFS_DEFAULT_NIOTHREADS); |
703 | } | | 701 | } |
704 | | | 702 | |
705 | if (mp->mnt_flag & MNT_UPDATE) { | | 703 | if (mp->mnt_flag & MNT_UPDATE) { |
706 | nmp = VFSTONFS(mp); | | 704 | nmp = VFSTONFS(mp); |
707 | /* update paths, file handles, etc, here XXX */ | | 705 | /* update paths, file handles, etc, here XXX */ |
708 | m_freem(nam); | | 706 | m_freem(nam); |
709 | return (0); | | 707 | return 0; |
710 | } else { | | | |
711 | nmp = kmem_zalloc(sizeof(*nmp), KM_SLEEP); | | | |
712 | mp->mnt_data = nmp; | | | |
713 | TAILQ_INIT(&nmp->nm_uidlruhead); | | | |
714 | TAILQ_INIT(&nmp->nm_bufq); | | | |
715 | rw_init(&nmp->nm_writeverflock); | | | |
716 | mutex_init(&nmp->nm_lock, MUTEX_DEFAULT, IPL_NONE); | | | |
717 | cv_init(&nmp->nm_rcvcv, "nfsrcv"); | | | |
718 | cv_init(&nmp->nm_sndcv, "nfssnd"); | | | |
719 | cv_init(&nmp->nm_aiocv, "nfsaio"); | | | |
720 | cv_init(&nmp->nm_disconcv, "nfsdis"); | | | |
721 | } | | 708 | } |
| | | 709 | nmp = kmem_zalloc(sizeof(*nmp), KM_SLEEP); |
| | | 710 | TAILQ_INIT(&nmp->nm_uidlruhead); |
| | | 711 | TAILQ_INIT(&nmp->nm_bufq); |
| | | 712 | rw_init(&nmp->nm_writeverflock); |
| | | 713 | mutex_init(&nmp->nm_lock, MUTEX_DEFAULT, IPL_NONE); |
| | | 714 | cv_init(&nmp->nm_rcvcv, "nfsrcv"); |
| | | 715 | cv_init(&nmp->nm_sndcv, "nfssnd"); |
| | | 716 | cv_init(&nmp->nm_aiocv, "nfsaio"); |
| | | 717 | cv_init(&nmp->nm_disconcv, "nfsdis"); |
| | | 718 | |
| | | 719 | mp->mnt_data = nmp; |
| | | 720 | mp->mnt_stat.f_namemax = NFS_MAXNAMLEN; |
722 | vfs_getnewfsid(mp); | | 721 | vfs_getnewfsid(mp); |
723 | nmp->nm_mountp = mp; | | 722 | nmp->nm_mountp = mp; |
724 | | | 723 | |
725 | #ifndef NFS_V2_ONLY | | 724 | #ifndef NFS_V2_ONLY |
726 | if ((argp->flags & NFSMNT_NFSV3) == 0) | | 725 | if ((argp->flags & NFSMNT_NFSV3) == 0) |
727 | #endif | | 726 | #endif |
728 | { | | 727 | { |
729 | if (argp->fhsize != NFSX_V2FH) { | | 728 | if (argp->fhsize != NFSX_V2FH) { |
730 | return EINVAL; | | 729 | return EINVAL; |
731 | } | | 730 | } |
732 | } | | 731 | } |
733 | | | 732 | |
734 | /* | | 733 | /* |
735 | * V2 can only handle 32 bit filesizes. For v3, nfs_fsinfo | | 734 | * V2 can only handle 32 bit filesizes. For v3, nfs_fsinfo |
736 | * will overwrite this. | | 735 | * will overwrite this. |
737 | */ | | 736 | */ |
738 | nmp->nm_maxfilesize = 0xffffffffLL; | | 737 | nmp->nm_maxfilesize = 0xffffffffLL; |
739 | | | 738 | |
740 | nmp->nm_timeo = NFS_TIMEO; | | 739 | nmp->nm_timeo = NFS_TIMEO; |
741 | nmp->nm_retry = NFS_RETRANS; | | 740 | nmp->nm_retry = NFS_RETRANS; |
742 | nmp->nm_wsize = NFS_WSIZE; | | 741 | nmp->nm_wsize = NFS_WSIZE; |
743 | nmp->nm_rsize = NFS_RSIZE; | | 742 | nmp->nm_rsize = NFS_RSIZE; |
744 | nmp->nm_readdirsize = NFS_READDIRSIZE; | | 743 | nmp->nm_readdirsize = NFS_READDIRSIZE; |
745 | nmp->nm_numgrps = NFS_MAXGRPS; | | 744 | nmp->nm_numgrps = NFS_MAXGRPS; |
746 | nmp->nm_readahead = NFS_DEFRAHEAD; | | 745 | nmp->nm_readahead = NFS_DEFRAHEAD; |
747 | nmp->nm_deadthresh = NFS_DEFDEADTHRESH; | | 746 | nmp->nm_deadthresh = NFS_DEFDEADTHRESH; |
748 | error = set_statvfs_info(pth, UIO_SYSSPACE, hst, UIO_SYSSPACE, | | 747 | error = set_statvfs_info(pth, UIO_SYSSPACE, hst, UIO_SYSSPACE, |
749 | mp->mnt_op->vfs_name, mp, l); | | 748 | mp->mnt_op->vfs_name, mp, l); |
750 | if (error) | | 749 | if (error) |
751 | goto bad; | | 750 | goto bad; |
752 | nmp->nm_nam = nam; | | 751 | nmp->nm_nam = nam; |
753 | | | 752 | |
754 | /* Set up the sockets and per-host congestion */ | | 753 | /* Set up the sockets and per-host congestion */ |
755 | nmp->nm_sotype = argp->sotype; | | 754 | nmp->nm_sotype = argp->sotype; |
756 | nmp->nm_soproto = argp->proto; | | 755 | nmp->nm_soproto = argp->proto; |
757 | | | 756 | |
758 | nfs_decode_args(nmp, argp, l); | | 757 | nfs_decode_args(nmp, argp, l); |
759 | | | 758 | |
760 | mp->mnt_fs_bshift = ffs(MIN(nmp->nm_rsize, nmp->nm_wsize)) - 1; | | 759 | mp->mnt_fs_bshift = ffs(MIN(nmp->nm_rsize, nmp->nm_wsize)) - 1; |
761 | mp->mnt_dev_bshift = DEV_BSHIFT; | | 760 | mp->mnt_dev_bshift = DEV_BSHIFT; |
762 | | | 761 | |
763 | /* | | 762 | /* |
764 | * For Connection based sockets (TCP,...) defer the connect until | | 763 | * For Connection based sockets (TCP,...) defer the connect until |
765 | * the first request, in case the server is not responding. | | 764 | * the first request, in case the server is not responding. |
766 | */ | | 765 | */ |
767 | if (nmp->nm_sotype == SOCK_DGRAM && | | 766 | if (nmp->nm_sotype == SOCK_DGRAM && |
768 | (error = nfs_connect(nmp, (struct nfsreq *)0, l))) | | 767 | (error = nfs_connect(nmp, (struct nfsreq *)0, l))) |
769 | goto bad; | | 768 | goto bad; |
770 | | | 769 | |
771 | /* | | 770 | /* |
772 | * This is silly, but it has to be set so that vinifod() works. | | 771 | * This is silly, but it has to be set so that vinifod() works. |
773 | * We do not want to do an nfs_statvfs() here since we can get | | 772 | * We do not want to do an nfs_statvfs() here since we can get |
774 | * stuck on a dead server and we are holding a lock on the mount | | 773 | * stuck on a dead server and we are holding a lock on the mount |
775 | * point. | | 774 | * point. |
776 | */ | | 775 | */ |
777 | mp->mnt_stat.f_iosize = NFS_MAXDGRAMDATA; | | 776 | mp->mnt_stat.f_iosize = NFS_MAXDGRAMDATA; |
778 | error = nfs_nget(mp, (nfsfh_t *)argp->fh, argp->fhsize, &np); | | 777 | error = nfs_nget(mp, (nfsfh_t *)argp->fh, argp->fhsize, &np); |
779 | if (error) | | 778 | if (error) |
780 | goto bad; | | 779 | goto bad; |
781 | vp = NFSTOV(np); | | 780 | vp = NFSTOV(np); |
782 | attrs = malloc(sizeof(struct vattr), M_TEMP, M_WAITOK); | | 781 | attrs = malloc(sizeof(struct vattr), M_TEMP, M_WAITOK); |
783 | VOP_GETATTR(vp, attrs, l->l_cred); | | 782 | VOP_GETATTR(vp, attrs, l->l_cred); |
784 | if ((nmp->nm_flag & NFSMNT_NFSV3) && (vp->v_type == VDIR)) { | | 783 | if ((nmp->nm_flag & NFSMNT_NFSV3) && (vp->v_type == VDIR)) { |
785 | cr = kauth_cred_alloc(); | | 784 | cr = kauth_cred_alloc(); |
786 | kauth_cred_setuid(cr, attrs->va_uid); | | 785 | kauth_cred_setuid(cr, attrs->va_uid); |
787 | kauth_cred_seteuid(cr, attrs->va_uid); | | 786 | kauth_cred_seteuid(cr, attrs->va_uid); |
788 | kauth_cred_setsvuid(cr, attrs->va_uid); | | 787 | kauth_cred_setsvuid(cr, attrs->va_uid); |
789 | kauth_cred_setgid(cr, attrs->va_gid); | | 788 | kauth_cred_setgid(cr, attrs->va_gid); |
790 | kauth_cred_setegid(cr, attrs->va_gid); | | 789 | kauth_cred_setegid(cr, attrs->va_gid); |
791 | kauth_cred_setsvgid(cr, attrs->va_gid); | | 790 | kauth_cred_setsvgid(cr, attrs->va_gid); |
792 | nfs_cookieheuristic(vp, &nmp->nm_iflag, l, cr); | | 791 | nfs_cookieheuristic(vp, &nmp->nm_iflag, l, cr); |
793 | kauth_cred_free(cr); | | 792 | kauth_cred_free(cr); |
794 | } | | 793 | } |
795 | free(attrs, M_TEMP); | | 794 | free(attrs, M_TEMP); |
796 | | | 795 | |
797 | /* | | 796 | /* |
798 | * A reference count is needed on the nfsnode representing the | | 797 | * A reference count is needed on the nfsnode representing the |
799 | * remote root. If this object is not persistent, then backward | | 798 | * remote root. If this object is not persistent, then backward |
800 | * traversals of the mount point (i.e. "..") will not work if | | 799 | * traversals of the mount point (i.e. "..") will not work if |
801 | * the nfsnode gets flushed out of the cache. Ufs does not have | | 800 | * the nfsnode gets flushed out of the cache. Ufs does not have |
802 | * this problem, because one can identify root inodes by their | | 801 | * this problem, because one can identify root inodes by their |
803 | * number == UFS_ROOTINO (2). So, just unlock, but no rele. | | 802 | * number == UFS_ROOTINO (2). So, just unlock, but no rele. |
804 | */ | | 803 | */ |
805 | | | 804 | |
806 | nmp->nm_vnode = vp; | | 805 | nmp->nm_vnode = vp; |
807 | if (vp->v_type == VNON) | | 806 | if (vp->v_type == VNON) |
808 | vp->v_type = VDIR; | | 807 | vp->v_type = VDIR; |
809 | vp->v_vflag |= VV_ROOT; | | 808 | vp->v_vflag |= VV_ROOT; |
810 | VOP_UNLOCK(vp); | | 809 | VOP_UNLOCK(vp); |
811 | *vpp = vp; | | 810 | *vpp = vp; |
812 | | | 811 | |
813 | snprintf(iosname, sizeof(iosname), "nfs%u", nfs_mount_count++); | | 812 | snprintf(iosname, sizeof(iosname), "nfs%u", nfs_mount_count++); |
814 | nmp->nm_stats = iostat_alloc(IOSTAT_NFS, nmp, iosname); | | 813 | nmp->nm_stats = iostat_alloc(IOSTAT_NFS, nmp, iosname); |
815 | | | 814 | |
816 | return (0); | | 815 | return (0); |
817 | bad: | | 816 | bad: |
818 | nfs_disconnect(nmp); | | 817 | nfs_disconnect(nmp); |
819 | rw_destroy(&nmp->nm_writeverflock); | | 818 | rw_destroy(&nmp->nm_writeverflock); |
820 | mutex_destroy(&nmp->nm_lock); | | 819 | mutex_destroy(&nmp->nm_lock); |
821 | cv_destroy(&nmp->nm_rcvcv); | | 820 | cv_destroy(&nmp->nm_rcvcv); |
822 | cv_destroy(&nmp->nm_sndcv); | | 821 | cv_destroy(&nmp->nm_sndcv); |
823 | cv_destroy(&nmp->nm_aiocv); | | 822 | cv_destroy(&nmp->nm_aiocv); |
824 | cv_destroy(&nmp->nm_disconcv); | | 823 | cv_destroy(&nmp->nm_disconcv); |
825 | kmem_free(nmp, sizeof(*nmp)); | | 824 | kmem_free(nmp, sizeof(*nmp)); |
826 | m_freem(nam); | | 825 | m_freem(nam); |
827 | return (error); | | 826 | return (error); |
828 | } | | 827 | } |
829 | | | 828 | |
830 | /* | | 829 | /* |
831 | * unmount system call | | 830 | * unmount system call |
832 | */ | | 831 | */ |
833 | int | | 832 | int |
834 | nfs_unmount(struct mount *mp, int mntflags) | | 833 | nfs_unmount(struct mount *mp, int mntflags) |
835 | { | | 834 | { |
836 | struct nfsmount *nmp = VFSTONFS(mp); | | 835 | struct nfsmount *nmp = VFSTONFS(mp); |
837 | struct vnode *vp; | | 836 | struct vnode *vp; |
838 | int error, flags = 0; | | 837 | int error, flags = 0; |
839 | | | 838 | |
840 | if (mntflags & MNT_FORCE) { | | 839 | if (mntflags & MNT_FORCE) { |
841 | mutex_enter(&nmp->nm_lock); | | 840 | mutex_enter(&nmp->nm_lock); |
842 | flags |= FORCECLOSE; | | 841 | flags |= FORCECLOSE; |
843 | nmp->nm_iflag |= NFSMNT_DISMNTFORCE; | | 842 | nmp->nm_iflag |= NFSMNT_DISMNTFORCE; |
844 | mutex_exit(&nmp->nm_lock); | | 843 | mutex_exit(&nmp->nm_lock); |
845 | | | 844 | |
846 | } | | 845 | } |
847 | | | 846 | |
848 | /* | | 847 | /* |
849 | * Goes something like this.. | | 848 | * Goes something like this.. |
850 | * - Check for activity on the root vnode (other than ourselves). | | 849 | * - Check for activity on the root vnode (other than ourselves). |
851 | * - Call vflush() to clear out vnodes for this file system, | | 850 | * - Call vflush() to clear out vnodes for this file system, |
852 | * except for the root vnode. | | 851 | * except for the root vnode. |
853 | * - Decrement reference on the vnode representing remote root. | | 852 | * - Decrement reference on the vnode representing remote root. |
854 | * - Close the socket | | 853 | * - Close the socket |
855 | * - Free up the data structures | | 854 | * - Free up the data structures |
856 | */ | | 855 | */ |
857 | /* | | 856 | /* |
858 | * We need to decrement the ref. count on the nfsnode representing | | 857 | * We need to decrement the ref. count on the nfsnode representing |
859 | * the remote root. See comment in mountnfs(). | | 858 | * the remote root. See comment in mountnfs(). |
860 | */ | | 859 | */ |
861 | vp = nmp->nm_vnode; | | 860 | vp = nmp->nm_vnode; |
862 | error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); | | 861 | error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
863 | if (error != 0) | | 862 | if (error != 0) |
864 | goto err; | | 863 | goto err; |
865 | | | 864 | |
866 | if ((mntflags & MNT_FORCE) == 0 && vrefcnt(vp) > 1) { | | 865 | if ((mntflags & MNT_FORCE) == 0 && vrefcnt(vp) > 1) { |
867 | VOP_UNLOCK(vp); | | 866 | VOP_UNLOCK(vp); |
868 | error = EBUSY; | | 867 | error = EBUSY; |
869 | goto err; | | 868 | goto err; |
870 | } | | 869 | } |
871 | | | 870 | |
872 | error = vflush(mp, vp, flags); | | 871 | error = vflush(mp, vp, flags); |
873 | if (error) { | | 872 | if (error) { |
874 | VOP_UNLOCK(vp); | | 873 | VOP_UNLOCK(vp); |
875 | goto err; | | 874 | goto err; |
876 | } | | 875 | } |
877 | | | 876 | |
878 | /* | | 877 | /* |
879 | * We are now committed to the unmount; mark the mount structure | | 878 | * We are now committed to the unmount; mark the mount structure |
880 | * as doomed so that any sleepers kicked awake by nfs_disconnect | | 879 | * as doomed so that any sleepers kicked awake by nfs_disconnect |
881 | * will go away cleanly. | | 880 | * will go away cleanly. |
882 | */ | | 881 | */ |
883 | nmp->nm_iflag |= NFSMNT_DISMNT; | | 882 | nmp->nm_iflag |= NFSMNT_DISMNT; |
884 | | | 883 | |
885 | /* | | 884 | /* |
886 | * No new async I/O will be added, but await for pending | | 885 | * No new async I/O will be added, but await for pending |
887 | * ones to drain. | | 886 | * ones to drain. |
888 | */ | | 887 | */ |
889 | while (nfs_iodbusy(nmp)) | | 888 | while (nfs_iodbusy(nmp)) |
890 | kpause("nfsumnt", false, hz, NULL); | | 889 | kpause("nfsumnt", false, hz, NULL); |
891 | | | 890 | |
892 | /* | | 891 | /* |
893 | * Clean up the stats... note that we carefully avoid decrementing | | 892 | * Clean up the stats... note that we carefully avoid decrementing |
894 | * nfs_mount_count here for good reason - we may not be unmounting | | 893 | * nfs_mount_count here for good reason - we may not be unmounting |
895 | * the last thing mounted. | | 894 | * the last thing mounted. |
896 | */ | | 895 | */ |
897 | iostat_free(nmp->nm_stats); | | 896 | iostat_free(nmp->nm_stats); |
898 | | | 897 | |
899 | /* | | 898 | /* |
900 | * There is one reference count to get rid of here | | 899 | * There is one reference count to get rid of here |
901 | * (see comment in mountnfs()). | | 900 | * (see comment in mountnfs()). |
902 | */ | | 901 | */ |
903 | VOP_UNLOCK(vp); | | 902 | VOP_UNLOCK(vp); |
904 | vgone(vp); | | 903 | vgone(vp); |
905 | nfs_disconnect(nmp); | | 904 | nfs_disconnect(nmp); |
906 | m_freem(nmp->nm_nam); | | 905 | m_freem(nmp->nm_nam); |
907 | | | 906 | |
908 | rw_destroy(&nmp->nm_writeverflock); | | 907 | rw_destroy(&nmp->nm_writeverflock); |
909 | mutex_destroy(&nmp->nm_lock); | | 908 | mutex_destroy(&nmp->nm_lock); |
910 | cv_destroy(&nmp->nm_rcvcv); | | 909 | cv_destroy(&nmp->nm_rcvcv); |
911 | cv_destroy(&nmp->nm_sndcv); | | 910 | cv_destroy(&nmp->nm_sndcv); |
912 | cv_destroy(&nmp->nm_aiocv); | | 911 | cv_destroy(&nmp->nm_aiocv); |
913 | cv_destroy(&nmp->nm_disconcv); | | 912 | cv_destroy(&nmp->nm_disconcv); |
914 | kmem_free(nmp, sizeof(*nmp)); | | 913 | kmem_free(nmp, sizeof(*nmp)); |
915 | return (0); | | 914 | return (0); |
916 | | | 915 | |
917 | err: | | 916 | err: |
918 | if (mntflags & MNT_FORCE) { | | 917 | if (mntflags & MNT_FORCE) { |
919 | mutex_enter(&nmp->nm_lock); | | 918 | mutex_enter(&nmp->nm_lock); |
920 | nmp->nm_iflag &= ~NFSMNT_DISMNTFORCE; | | 919 | nmp->nm_iflag &= ~NFSMNT_DISMNTFORCE; |
921 | mutex_exit(&nmp->nm_lock); | | 920 | mutex_exit(&nmp->nm_lock); |
922 | } | | 921 | } |
923 | | | 922 | |
924 | return error; | | 923 | return error; |
925 | } | | 924 | } |
926 | | | 925 | |
927 | /* | | 926 | /* |
928 | * Return root of a filesystem | | 927 | * Return root of a filesystem |
929 | */ | | 928 | */ |
930 | int | | 929 | int |
931 | nfs_root(struct mount *mp, int lktype, struct vnode **vpp) | | 930 | nfs_root(struct mount *mp, int lktype, struct vnode **vpp) |
932 | { | | 931 | { |
933 | struct vnode *vp; | | 932 | struct vnode *vp; |
934 | struct nfsmount *nmp; | | 933 | struct nfsmount *nmp; |
935 | int error; | | 934 | int error; |
936 | | | 935 | |
937 | nmp = VFSTONFS(mp); | | 936 | nmp = VFSTONFS(mp); |
938 | vp = nmp->nm_vnode; | | 937 | vp = nmp->nm_vnode; |
939 | vref(vp); | | 938 | vref(vp); |
940 | error = vn_lock(vp, lktype | LK_RETRY); | | 939 | error = vn_lock(vp, lktype | LK_RETRY); |
941 | if (error != 0) { | | 940 | if (error != 0) { |
942 | vrele(vp); | | 941 | vrele(vp); |
943 | return error; | | 942 | return error; |
944 | } | | 943 | } |
945 | *vpp = vp; | | 944 | *vpp = vp; |
946 | return (0); | | 945 | return (0); |
947 | } | | 946 | } |
948 | | | 947 | |
949 | extern int syncprt; | | 948 | extern int syncprt; |
950 | | | 949 | |
951 | static bool | | 950 | static bool |
952 | nfs_sync_selector(void *cl, struct vnode *vp) | | 951 | nfs_sync_selector(void *cl, struct vnode *vp) |
953 | { | | 952 | { |
954 | | | 953 | |
955 | KASSERT(mutex_owned(vp->v_interlock)); | | 954 | KASSERT(mutex_owned(vp->v_interlock)); |
956 | | | 955 | |
957 | return !LIST_EMPTY(&vp->v_dirtyblkhd) || | | 956 | return !LIST_EMPTY(&vp->v_dirtyblkhd) || |
958 | (vp->v_iflag & VI_ONWORKLST) != 0; | | 957 | (vp->v_iflag & VI_ONWORKLST) != 0; |
959 | } | | 958 | } |
960 | | | 959 | |
961 | /* | | 960 | /* |
962 | * Flush out the buffer cache | | 961 | * Flush out the buffer cache |
963 | */ | | 962 | */ |
964 | /* ARGSUSED */ | | 963 | /* ARGSUSED */ |
965 | int | | 964 | int |
966 | nfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) | | 965 | nfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred) |
967 | { | | 966 | { |
968 | struct vnode *vp; | | 967 | struct vnode *vp; |
969 | struct vnode_iterator *marker; | | 968 | struct vnode_iterator *marker; |
970 | int error, allerror = 0; | | 969 | int error, allerror = 0; |
971 | | | 970 | |
972 | /* | | 971 | /* |
973 | * Force stale buffer cache information to be flushed. | | 972 | * Force stale buffer cache information to be flushed. |
974 | */ | | 973 | */ |
975 | vfs_vnode_iterator_init(mp, &marker); | | 974 | vfs_vnode_iterator_init(mp, &marker); |
976 | while ((vp = vfs_vnode_iterator_next(marker, nfs_sync_selector, | | 975 | while ((vp = vfs_vnode_iterator_next(marker, nfs_sync_selector, |
977 | NULL))) | | 976 | NULL))) |
978 | { | | 977 | { |
979 | error = vn_lock(vp, LK_EXCLUSIVE); | | 978 | error = vn_lock(vp, LK_EXCLUSIVE); |
980 | if (error) { | | 979 | if (error) { |
981 | vrele(vp); | | 980 | vrele(vp); |
982 | continue; | | 981 | continue; |
983 | } | | 982 | } |
984 | error = VOP_FSYNC(vp, cred, | | 983 | error = VOP_FSYNC(vp, cred, |
985 | waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0); | | 984 | waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0); |
986 | if (error) | | 985 | if (error) |
987 | allerror = error; | | 986 | allerror = error; |
988 | vput(vp); | | 987 | vput(vp); |
989 | } | | 988 | } |
990 | vfs_vnode_iterator_destroy(marker); | | 989 | vfs_vnode_iterator_destroy(marker); |
991 | return allerror; | | 990 | return allerror; |
992 | } | | 991 | } |
993 | | | 992 | |
994 | /* | | 993 | /* |
995 | * NFS flat namespace lookup. | | 994 | * NFS flat namespace lookup. |
996 | * Currently unsupported. | | 995 | * Currently unsupported. |
997 | */ | | 996 | */ |
998 | /* ARGSUSED */ | | 997 | /* ARGSUSED */ |
999 | int | | 998 | int |
1000 | nfs_vget(struct mount *mp, ino_t ino, int lktype, struct vnode **vpp) | | 999 | nfs_vget(struct mount *mp, ino_t ino, int lktype, struct vnode **vpp) |
1001 | { | | 1000 | { |
1002 | | | 1001 | |
1003 | return (EOPNOTSUPP); | | 1002 | return (EOPNOTSUPP); |
1004 | } | | 1003 | } |
1005 | | | 1004 | |
1006 | /* | | 1005 | /* |
1007 | * Do that sysctl thang... | | 1006 | * Do that sysctl thang... |
1008 | */ | | 1007 | */ |
1009 | static int | | 1008 | static int |
1010 | sysctl_vfs_nfs_iothreads(SYSCTLFN_ARGS) | | 1009 | sysctl_vfs_nfs_iothreads(SYSCTLFN_ARGS) |
1011 | { | | 1010 | { |
1012 | struct sysctlnode node; | | 1011 | struct sysctlnode node; |
1013 | int val; | | 1012 | int val; |
1014 | int error; | | 1013 | int error; |
1015 | | | 1014 | |
1016 | val = nfs_niothreads; | | 1015 | val = nfs_niothreads; |
1017 | node = *rnode; | | 1016 | node = *rnode; |
1018 | node.sysctl_data = &val; | | 1017 | node.sysctl_data = &val; |
1019 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | | 1018 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); |
1020 | if (error || newp == NULL) | | 1019 | if (error || newp == NULL) |
1021 | return error; | | 1020 | return error; |
1022 | | | 1021 | |
1023 | return nfs_set_niothreads(val); | | 1022 | return nfs_set_niothreads(val); |
1024 | } | | 1023 | } |
1025 | | | 1024 | |
1026 | SYSCTL_SETUP(nfs_sysctl_init, "nfs sysctl") | | 1025 | SYSCTL_SETUP(nfs_sysctl_init, "nfs sysctl") |
1027 | { | | 1026 | { |
1028 | | | 1027 | |
1029 | sysctl_createv(clog, 0, NULL, NULL, | | 1028 | sysctl_createv(clog, 0, NULL, NULL, |
1030 | CTLFLAG_PERMANENT, | | 1029 | CTLFLAG_PERMANENT, |
1031 | CTLTYPE_NODE, "nfs", | | 1030 | CTLTYPE_NODE, "nfs", |
1032 | SYSCTL_DESCR("NFS vfs options"), | | 1031 | SYSCTL_DESCR("NFS vfs options"), |
1033 | NULL, 0, NULL, 0, | | 1032 | NULL, 0, NULL, 0, |
1034 | CTL_VFS, 2, CTL_EOL); | | 1033 | CTL_VFS, 2, CTL_EOL); |
1035 | /* | | 1034 | /* |
1036 | * XXX the "2" above could be dynamic, thereby eliminating one | | 1035 | * XXX the "2" above could be dynamic, thereby eliminating one |
1037 | * more instance of the "number to vfs" mapping problem, but | | 1036 | * more instance of the "number to vfs" mapping problem, but |
1038 | * "2" is the order as taken from sys/mount.h | | 1037 | * "2" is the order as taken from sys/mount.h |
1039 | */ | | 1038 | */ |
1040 | | | 1039 | |
1041 | sysctl_createv(clog, 0, NULL, NULL, | | 1040 | sysctl_createv(clog, 0, NULL, NULL, |
1042 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 1041 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
1043 | CTLTYPE_STRUCT, "nfsstats", | | 1042 | CTLTYPE_STRUCT, "nfsstats", |
1044 | SYSCTL_DESCR("NFS operation statistics"), | | 1043 | SYSCTL_DESCR("NFS operation statistics"), |
1045 | NULL, 0, &nfsstats, sizeof(nfsstats), | | 1044 | NULL, 0, &nfsstats, sizeof(nfsstats), |
1046 | CTL_VFS, 2, NFS_NFSSTATS, CTL_EOL); | | 1045 | CTL_VFS, 2, NFS_NFSSTATS, CTL_EOL); |
1047 | sysctl_createv(clog, 0, NULL, NULL, | | 1046 | sysctl_createv(clog, 0, NULL, NULL, |
1048 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 1047 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
1049 | CTLTYPE_INT, "iothreads", | | 1048 | CTLTYPE_INT, "iothreads", |
1050 | SYSCTL_DESCR("Number of NFS client processes desired"), | | 1049 | SYSCTL_DESCR("Number of NFS client processes desired"), |
1051 | sysctl_vfs_nfs_iothreads, 0, NULL, 0, | | 1050 | sysctl_vfs_nfs_iothreads, 0, NULL, 0, |
1052 | CTL_VFS, 2, NFS_IOTHREADS, CTL_EOL); | | 1051 | CTL_VFS, 2, NFS_IOTHREADS, CTL_EOL); |
1053 | } | | 1052 | } |
1054 | | | 1053 | |
1055 | /* ARGSUSED */ | | 1054 | /* ARGSUSED */ |
1056 | int | | 1055 | int |
1057 | nfs_fhtovp(struct mount *mp, struct fid *fid, int lktype, struct vnode **vpp) | | 1056 | nfs_fhtovp(struct mount *mp, struct fid *fid, int lktype, struct vnode **vpp) |
1058 | { | | 1057 | { |
1059 | size_t fidsize; | | 1058 | size_t fidsize; |
1060 | size_t fhsize; | | 1059 | size_t fhsize; |
1061 | struct nfsnode *np; | | 1060 | struct nfsnode *np; |
1062 | int error; | | 1061 | int error; |
1063 | struct vattr va; | | 1062 | struct vattr va; |
1064 | | | 1063 | |
1065 | fidsize = fid->fid_len; | | 1064 | fidsize = fid->fid_len; |
1066 | if (fidsize < sizeof(*fid)) { | | 1065 | if (fidsize < sizeof(*fid)) { |
1067 | return EINVAL; | | 1066 | return EINVAL; |
1068 | } | | 1067 | } |
1069 | fhsize = fidsize - sizeof(*fid); | | 1068 | fhsize = fidsize - sizeof(*fid); |
1070 | if ((fhsize % NFSX_UNSIGNED) != 0) { | | 1069 | if ((fhsize % NFSX_UNSIGNED) != 0) { |
1071 | return EINVAL; | | 1070 | return EINVAL; |
1072 | } | | 1071 | } |
1073 | if ((VFSTONFS(mp)->nm_flag & NFSMNT_NFSV3) != 0) { | | 1072 | if ((VFSTONFS(mp)->nm_flag & NFSMNT_NFSV3) != 0) { |
1074 | if (fhsize > NFSX_V3FHMAX || fhsize == 0) { | | 1073 | if (fhsize > NFSX_V3FHMAX || fhsize == 0) { |
1075 | return EINVAL; | | 1074 | return EINVAL; |
1076 | } | | 1075 | } |
1077 | } else { | | 1076 | } else { |
1078 | if (fhsize != NFSX_V2FH) { | | 1077 | if (fhsize != NFSX_V2FH) { |
1079 | return EINVAL; | | 1078 | return EINVAL; |
1080 | } | | 1079 | } |
1081 | } | | 1080 | } |
1082 | /* XXX lktype ignored */ | | 1081 | /* XXX lktype ignored */ |
1083 | error = nfs_nget(mp, (void *)fid->fid_data, fhsize, &np); | | 1082 | error = nfs_nget(mp, (void *)fid->fid_data, fhsize, &np); |
1084 | if (error) { | | 1083 | if (error) { |
1085 | return error; | | 1084 | return error; |
1086 | } | | 1085 | } |
1087 | *vpp = NFSTOV(np); | | 1086 | *vpp = NFSTOV(np); |
1088 | error = VOP_GETATTR(*vpp, &va, kauth_cred_get()); | | 1087 | error = VOP_GETATTR(*vpp, &va, kauth_cred_get()); |
1089 | if (error != 0) { | | 1088 | if (error != 0) { |
1090 | vput(*vpp); | | 1089 | vput(*vpp); |
1091 | *vpp = NULLVP; | | 1090 | *vpp = NULLVP; |
1092 | } | | 1091 | } |
1093 | return error; | | 1092 | return error; |
1094 | } | | 1093 | } |
1095 | | | 1094 | |
1096 | /* ARGSUSED */ | | 1095 | /* ARGSUSED */ |
1097 | int | | 1096 | int |
1098 | nfs_vptofh(struct vnode *vp, struct fid *buf, size_t *bufsize) | | 1097 | nfs_vptofh(struct vnode *vp, struct fid *buf, size_t *bufsize) |
1099 | { | | 1098 | { |
1100 | struct nfsnode *np; | | 1099 | struct nfsnode *np; |
1101 | struct fid *fid; | | 1100 | struct fid *fid; |
1102 | size_t fidsize; | | 1101 | size_t fidsize; |
1103 | int error = 0; | | 1102 | int error = 0; |
1104 | | | 1103 | |
1105 | np = VTONFS(vp); | | 1104 | np = VTONFS(vp); |
1106 | fidsize = sizeof(*fid) + np->n_fhsize; | | 1105 | fidsize = sizeof(*fid) + np->n_fhsize; |
1107 | if (*bufsize < fidsize) { | | 1106 | if (*bufsize < fidsize) { |
1108 | error = E2BIG; | | 1107 | error = E2BIG; |
1109 | } | | 1108 | } |
1110 | *bufsize = fidsize; | | 1109 | *bufsize = fidsize; |
1111 | if (error == 0) { | | 1110 | if (error == 0) { |
1112 | struct fid fid_store; | | 1111 | struct fid fid_store; |
1113 | | | 1112 | |
1114 | fid = &fid_store; | | 1113 | fid = &fid_store; |
1115 | memset(fid, 0, sizeof(*fid)); | | 1114 | memset(fid, 0, sizeof(*fid)); |
1116 | fid->fid_len = fidsize; | | 1115 | fid->fid_len = fidsize; |
1117 | memcpy(buf, fid, sizeof(*fid)); | | 1116 | memcpy(buf, fid, sizeof(*fid)); |
1118 | memcpy(buf->fid_data, np->n_fhp, np->n_fhsize); | | 1117 | memcpy(buf->fid_data, np->n_fhp, np->n_fhsize); |
1119 | } | | 1118 | } |
1120 | return error; | | 1119 | return error; |
1121 | } | | 1120 | } |
1122 | | | 1121 | |
1123 | /* | | 1122 | /* |
1124 | * Vfs start routine, a no-op. | | 1123 | * Vfs start routine, a no-op. |
1125 | */ | | 1124 | */ |
1126 | /* ARGSUSED */ | | 1125 | /* ARGSUSED */ |
1127 | int | | 1126 | int |
1128 | nfs_start(struct mount *mp, int flags) | | 1127 | nfs_start(struct mount *mp, int flags) |
1129 | { | | 1128 | { |
1130 | | | 1129 | |
1131 | return (0); | | 1130 | return (0); |
1132 | } | | 1131 | } |
1133 | | | 1132 | |
1134 | /* | | 1133 | /* |
1135 | * Called once at VFS init to initialize client-specific data structures. | | 1134 | * Called once at VFS init to initialize client-specific data structures. |
1136 | */ | | 1135 | */ |
1137 | void | | 1136 | void |
1138 | nfs_vfs_init(void) | | 1137 | nfs_vfs_init(void) |
1139 | { | | 1138 | { |
1140 | | | 1139 | |
1141 | /* Initialize NFS server / client shared data. */ | | 1140 | /* Initialize NFS server / client shared data. */ |
1142 | nfs_init(); | | 1141 | nfs_init(); |
1143 | nfs_node_init(); | | 1142 | nfs_node_init(); |
1144 | | | 1143 | |
1145 | /* Initialize the kqueue structures */ | | 1144 | /* Initialize the kqueue structures */ |
1146 | nfs_kqinit(); | | 1145 | nfs_kqinit(); |
1147 | /* Initialize the iod structures */ | | 1146 | /* Initialize the iod structures */ |
1148 | nfs_iodinit(); | | 1147 | nfs_iodinit(); |
1149 | | | 1148 | |
1150 | nfs_commitsize = uvmexp.npages << (PAGE_SHIFT - 4); | | 1149 | nfs_commitsize = uvmexp.npages << (PAGE_SHIFT - 4); |
1151 | } | | 1150 | } |
1152 | | | 1151 | |
1153 | void | | 1152 | void |
1154 | nfs_vfs_done(void) | | 1153 | nfs_vfs_done(void) |
1155 | { | | 1154 | { |
1156 | | | 1155 | |
1157 | nfs_node_done(); | | 1156 | nfs_node_done(); |
1158 | nfs_kqfini(); | | 1157 | nfs_kqfini(); |
1159 | nfs_iodfini(); | | 1158 | nfs_iodfini(); |
1160 | nfs_fini(); | | 1159 | nfs_fini(); |
1161 | } | | 1160 | } |