| @@ -1,1227 +1,1231 @@ | | | @@ -1,1227 +1,1231 @@ |
1 | /* $NetBSD: nfs_subs.c,v 1.237 2020/02/24 20:18:53 ad Exp $ */ | | 1 | /* $NetBSD: nfs_subs.c,v 1.238 2020/03/08 22:12:42 mgorny Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1989, 1993 | | 4 | * Copyright (c) 1989, 1993 |
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_subs.c 8.8 (Berkeley) 5/22/95 | | 34 | * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95 |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | /* | | 37 | /* |
38 | * Copyright 2000 Wasabi Systems, Inc. | | 38 | * Copyright 2000 Wasabi Systems, Inc. |
39 | * All rights reserved. | | 39 | * All rights reserved. |
40 | * | | 40 | * |
41 | * Written by Frank van der Linden for Wasabi Systems, Inc. | | 41 | * Written by Frank van der Linden for Wasabi Systems, Inc. |
42 | * | | 42 | * |
43 | * Redistribution and use in source and binary forms, with or without | | 43 | * Redistribution and use in source and binary forms, with or without |
44 | * modification, are permitted provided that the following conditions | | 44 | * modification, are permitted provided that the following conditions |
45 | * are met: | | 45 | * are met: |
46 | * 1. Redistributions of source code must retain the above copyright | | 46 | * 1. Redistributions of source code must retain the above copyright |
47 | * notice, this list of conditions and the following disclaimer. | | 47 | * notice, this list of conditions and the following disclaimer. |
48 | * 2. Redistributions in binary form must reproduce the above copyright | | 48 | * 2. Redistributions in binary form must reproduce the above copyright |
49 | * notice, this list of conditions and the following disclaimer in the | | 49 | * notice, this list of conditions and the following disclaimer in the |
50 | * documentation and/or other materials provided with the distribution. | | 50 | * documentation and/or other materials provided with the distribution. |
51 | * 3. All advertising materials mentioning features or use of this software | | 51 | * 3. All advertising materials mentioning features or use of this software |
52 | * must display the following acknowledgement: | | 52 | * must display the following acknowledgement: |
53 | * This product includes software developed for the NetBSD Project by | | 53 | * This product includes software developed for the NetBSD Project by |
54 | * Wasabi Systems, Inc. | | 54 | * Wasabi Systems, Inc. |
55 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse | | 55 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
56 | * or promote products derived from this software without specific prior | | 56 | * or promote products derived from this software without specific prior |
57 | * written permission. | | 57 | * written permission. |
58 | * | | 58 | * |
59 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | | 59 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
61 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 61 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
62 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 62 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
63 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 63 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
64 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 64 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
65 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 65 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
66 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 66 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
67 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 67 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
68 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 68 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
69 | * POSSIBILITY OF SUCH DAMAGE. | | 69 | * POSSIBILITY OF SUCH DAMAGE. |
70 | */ | | 70 | */ |
71 | | | 71 | |
72 | #include <sys/cdefs.h> | | 72 | #include <sys/cdefs.h> |
73 | __KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.237 2020/02/24 20:18:53 ad Exp $"); | | 73 | __KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.238 2020/03/08 22:12:42 mgorny Exp $"); |
74 | | | 74 | |
75 | #ifdef _KERNEL_OPT | | 75 | #ifdef _KERNEL_OPT |
76 | #include "opt_nfs.h" | | 76 | #include "opt_nfs.h" |
77 | #endif | | 77 | #endif |
78 | | | 78 | |
79 | /* | | 79 | /* |
80 | * These functions support the macros and help fiddle mbuf chains for | | 80 | * These functions support the macros and help fiddle mbuf chains for |
81 | * the nfs op functions. They do things like create the rpc header and | | 81 | * the nfs op functions. They do things like create the rpc header and |
82 | * copy data between mbuf chains and uio lists. | | 82 | * copy data between mbuf chains and uio lists. |
83 | */ | | 83 | */ |
84 | #include <sys/param.h> | | 84 | #include <sys/param.h> |
85 | #include <sys/proc.h> | | 85 | #include <sys/proc.h> |
86 | #include <sys/systm.h> | | 86 | #include <sys/systm.h> |
87 | #include <sys/kernel.h> | | 87 | #include <sys/kernel.h> |
88 | #include <sys/kmem.h> | | 88 | #include <sys/kmem.h> |
89 | #include <sys/mount.h> | | 89 | #include <sys/mount.h> |
90 | #include <sys/vnode.h> | | 90 | #include <sys/vnode.h> |
91 | #include <sys/namei.h> | | 91 | #include <sys/namei.h> |
92 | #include <sys/mbuf.h> | | 92 | #include <sys/mbuf.h> |
93 | #include <sys/socket.h> | | 93 | #include <sys/socket.h> |
94 | #include <sys/stat.h> | | 94 | #include <sys/stat.h> |
95 | #include <sys/filedesc.h> | | 95 | #include <sys/filedesc.h> |
96 | #include <sys/time.h> | | 96 | #include <sys/time.h> |
97 | #include <sys/dirent.h> | | 97 | #include <sys/dirent.h> |
98 | #include <sys/once.h> | | 98 | #include <sys/once.h> |
99 | #include <sys/kauth.h> | | 99 | #include <sys/kauth.h> |
100 | #include <sys/atomic.h> | | 100 | #include <sys/atomic.h> |
101 | #include <sys/cprng.h> | | 101 | #include <sys/cprng.h> |
102 | | | 102 | |
103 | #include <uvm/uvm.h> | | 103 | #include <uvm/uvm.h> |
104 | #include <uvm/uvm_page_array.h> | | 104 | #include <uvm/uvm_page_array.h> |
105 | | | 105 | |
106 | #include <nfs/rpcv2.h> | | 106 | #include <nfs/rpcv2.h> |
107 | #include <nfs/nfsproto.h> | | 107 | #include <nfs/nfsproto.h> |
108 | #include <nfs/nfsnode.h> | | 108 | #include <nfs/nfsnode.h> |
109 | #include <nfs/nfs.h> | | 109 | #include <nfs/nfs.h> |
110 | #include <nfs/xdr_subs.h> | | 110 | #include <nfs/xdr_subs.h> |
111 | #include <nfs/nfsm_subs.h> | | 111 | #include <nfs/nfsm_subs.h> |
112 | #include <nfs/nfsmount.h> | | 112 | #include <nfs/nfsmount.h> |
113 | #include <nfs/nfsrtt.h> | | 113 | #include <nfs/nfsrtt.h> |
114 | #include <nfs/nfs_var.h> | | 114 | #include <nfs/nfs_var.h> |
115 | | | 115 | |
116 | #include <miscfs/specfs/specdev.h> | | 116 | #include <miscfs/specfs/specdev.h> |
117 | | | 117 | |
118 | #include <netinet/in.h> | | 118 | #include <netinet/in.h> |
119 | | | 119 | |
120 | static u_int32_t nfs_xid; | | 120 | static u_int32_t nfs_xid; |
121 | | | 121 | |
122 | int nuidhash_max = NFS_MAXUIDHASH; | | 122 | int nuidhash_max = NFS_MAXUIDHASH; |
123 | /* | | 123 | /* |
124 | * Data items converted to xdr at startup, since they are constant | | 124 | * Data items converted to xdr at startup, since they are constant |
125 | * This is kinda hokey, but may save a little time doing byte swaps | | 125 | * This is kinda hokey, but may save a little time doing byte swaps |
126 | */ | | 126 | */ |
127 | u_int32_t nfs_xdrneg1; | | 127 | u_int32_t nfs_xdrneg1; |
128 | u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr, | | 128 | u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr, |
129 | rpc_mismatch, rpc_auth_unix, rpc_msgaccepted, | | 129 | rpc_mismatch, rpc_auth_unix, rpc_msgaccepted, |
130 | rpc_auth_kerb; | | 130 | rpc_auth_kerb; |
131 | u_int32_t nfs_prog, nfs_true, nfs_false; | | 131 | u_int32_t nfs_prog, nfs_true, nfs_false; |
132 | | | 132 | |
133 | /* And other global data */ | | 133 | /* And other global data */ |
134 | const nfstype nfsv2_type[9] = | | 134 | const nfstype nfsv2_type[9] = |
135 | { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFNON, NFCHR, NFNON }; | | 135 | { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFNON, NFCHR, NFNON }; |
136 | const nfstype nfsv3_type[9] = | | 136 | const nfstype nfsv3_type[9] = |
137 | { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFSOCK, NFFIFO, NFNON }; | | 137 | { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFSOCK, NFFIFO, NFNON }; |
138 | const enum vtype nv2tov_type[8] = | | 138 | const enum vtype nv2tov_type[8] = |
139 | { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON }; | | 139 | { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON }; |
140 | const enum vtype nv3tov_type[8] = | | 140 | const enum vtype nv3tov_type[8] = |
141 | { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO }; | | 141 | { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO }; |
142 | int nfs_ticks; | | 142 | int nfs_ticks; |
143 | | | 143 | |
144 | /* NFS client/server stats. */ | | 144 | /* NFS client/server stats. */ |
145 | struct nfsstats nfsstats; | | 145 | struct nfsstats nfsstats; |
146 | | | 146 | |
147 | /* | | 147 | /* |
148 | * Mapping of old NFS Version 2 RPC numbers to generic numbers. | | 148 | * Mapping of old NFS Version 2 RPC numbers to generic numbers. |
149 | */ | | 149 | */ |
150 | const int nfsv3_procid[NFS_NPROCS] = { | | 150 | const int nfsv3_procid[NFS_NPROCS] = { |
151 | NFSPROC_NULL, | | 151 | NFSPROC_NULL, |
152 | NFSPROC_GETATTR, | | 152 | NFSPROC_GETATTR, |
153 | NFSPROC_SETATTR, | | 153 | NFSPROC_SETATTR, |
154 | NFSPROC_NOOP, | | 154 | NFSPROC_NOOP, |
155 | NFSPROC_LOOKUP, | | 155 | NFSPROC_LOOKUP, |
156 | NFSPROC_READLINK, | | 156 | NFSPROC_READLINK, |
157 | NFSPROC_READ, | | 157 | NFSPROC_READ, |
158 | NFSPROC_NOOP, | | 158 | NFSPROC_NOOP, |
159 | NFSPROC_WRITE, | | 159 | NFSPROC_WRITE, |
160 | NFSPROC_CREATE, | | 160 | NFSPROC_CREATE, |
161 | NFSPROC_REMOVE, | | 161 | NFSPROC_REMOVE, |
162 | NFSPROC_RENAME, | | 162 | NFSPROC_RENAME, |
163 | NFSPROC_LINK, | | 163 | NFSPROC_LINK, |
164 | NFSPROC_SYMLINK, | | 164 | NFSPROC_SYMLINK, |
165 | NFSPROC_MKDIR, | | 165 | NFSPROC_MKDIR, |
166 | NFSPROC_RMDIR, | | 166 | NFSPROC_RMDIR, |
167 | NFSPROC_READDIR, | | 167 | NFSPROC_READDIR, |
168 | NFSPROC_FSSTAT, | | 168 | NFSPROC_FSSTAT, |
169 | NFSPROC_NOOP, | | 169 | NFSPROC_NOOP, |
170 | NFSPROC_NOOP, | | 170 | NFSPROC_NOOP, |
171 | NFSPROC_NOOP, | | 171 | NFSPROC_NOOP, |
172 | NFSPROC_NOOP, | | 172 | NFSPROC_NOOP, |
173 | NFSPROC_NOOP | | 173 | NFSPROC_NOOP |
174 | }; | | 174 | }; |
175 | | | 175 | |
176 | /* | | 176 | /* |
177 | * and the reverse mapping from generic to Version 2 procedure numbers | | 177 | * and the reverse mapping from generic to Version 2 procedure numbers |
178 | */ | | 178 | */ |
179 | const int nfsv2_procid[NFS_NPROCS] = { | | 179 | const int nfsv2_procid[NFS_NPROCS] = { |
180 | NFSV2PROC_NULL, | | 180 | NFSV2PROC_NULL, |
181 | NFSV2PROC_GETATTR, | | 181 | NFSV2PROC_GETATTR, |
182 | NFSV2PROC_SETATTR, | | 182 | NFSV2PROC_SETATTR, |
183 | NFSV2PROC_LOOKUP, | | 183 | NFSV2PROC_LOOKUP, |
184 | NFSV2PROC_NOOP, | | 184 | NFSV2PROC_NOOP, |
185 | NFSV2PROC_READLINK, | | 185 | NFSV2PROC_READLINK, |
186 | NFSV2PROC_READ, | | 186 | NFSV2PROC_READ, |
187 | NFSV2PROC_WRITE, | | 187 | NFSV2PROC_WRITE, |
188 | NFSV2PROC_CREATE, | | 188 | NFSV2PROC_CREATE, |
189 | NFSV2PROC_MKDIR, | | 189 | NFSV2PROC_MKDIR, |
190 | NFSV2PROC_SYMLINK, | | 190 | NFSV2PROC_SYMLINK, |
191 | NFSV2PROC_CREATE, | | 191 | NFSV2PROC_CREATE, |
192 | NFSV2PROC_REMOVE, | | 192 | NFSV2PROC_REMOVE, |
193 | NFSV2PROC_RMDIR, | | 193 | NFSV2PROC_RMDIR, |
194 | NFSV2PROC_RENAME, | | 194 | NFSV2PROC_RENAME, |
195 | NFSV2PROC_LINK, | | 195 | NFSV2PROC_LINK, |
196 | NFSV2PROC_READDIR, | | 196 | NFSV2PROC_READDIR, |
197 | NFSV2PROC_NOOP, | | 197 | NFSV2PROC_NOOP, |
198 | NFSV2PROC_STATFS, | | 198 | NFSV2PROC_STATFS, |
199 | NFSV2PROC_NOOP, | | 199 | NFSV2PROC_NOOP, |
200 | NFSV2PROC_NOOP, | | 200 | NFSV2PROC_NOOP, |
201 | NFSV2PROC_NOOP, | | 201 | NFSV2PROC_NOOP, |
202 | NFSV2PROC_NOOP, | | 202 | NFSV2PROC_NOOP, |
203 | }; | | 203 | }; |
204 | | | 204 | |
205 | /* | | 205 | /* |
206 | * Maps errno values to nfs error numbers. | | 206 | * Maps errno values to nfs error numbers. |
207 | * Use NFSERR_IO as the catch all for ones not specifically defined in | | 207 | * Use NFSERR_IO as the catch all for ones not specifically defined in |
208 | * RFC 1094. | | 208 | * RFC 1094. |
209 | */ | | 209 | */ |
210 | static const u_char nfsrv_v2errmap[ELAST] = { | | 210 | static const u_char nfsrv_v2errmap[] = { |
211 | NFSERR_PERM, NFSERR_NOENT, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 211 | NFSERR_PERM, NFSERR_NOENT, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
212 | NFSERR_NXIO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 212 | NFSERR_NXIO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
213 | NFSERR_IO, NFSERR_IO, NFSERR_ACCES, NFSERR_IO, NFSERR_IO, | | 213 | NFSERR_IO, NFSERR_IO, NFSERR_ACCES, NFSERR_IO, NFSERR_IO, |
214 | NFSERR_IO, NFSERR_EXIST, NFSERR_IO, NFSERR_NODEV, NFSERR_NOTDIR, | | 214 | NFSERR_IO, NFSERR_EXIST, NFSERR_IO, NFSERR_NODEV, NFSERR_NOTDIR, |
215 | NFSERR_ISDIR, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 215 | NFSERR_ISDIR, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
216 | NFSERR_IO, NFSERR_FBIG, NFSERR_NOSPC, NFSERR_IO, NFSERR_ROFS, | | 216 | NFSERR_IO, NFSERR_FBIG, NFSERR_NOSPC, NFSERR_IO, NFSERR_ROFS, |
217 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 217 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
218 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 218 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
219 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 219 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
220 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 220 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
221 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 221 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
222 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 222 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
223 | NFSERR_IO, NFSERR_IO, NFSERR_NAMETOL, NFSERR_IO, NFSERR_IO, | | 223 | NFSERR_IO, NFSERR_IO, NFSERR_NAMETOL, NFSERR_IO, NFSERR_IO, |
224 | NFSERR_NOTEMPTY, NFSERR_IO, NFSERR_IO, NFSERR_DQUOT, NFSERR_STALE, | | 224 | NFSERR_NOTEMPTY, NFSERR_IO, NFSERR_IO, NFSERR_DQUOT, NFSERR_STALE, |
225 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 225 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
226 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | | 226 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
227 | NFSERR_IO, NFSERR_IO, | | 227 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
| | | 228 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
| | | 229 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, |
| | | 230 | NFSERR_IO, NFSERR_IO, NFSERR_IO |
228 | }; | | 231 | }; |
| | | 232 | __CTASSERT(__arraycount(nfsrv_v2errmap) == ELAST); |
229 | | | 233 | |
230 | /* | | 234 | /* |
231 | * Maps errno values to nfs error numbers. | | 235 | * Maps errno values to nfs error numbers. |
232 | * Although it is not obvious whether or not NFS clients really care if | | 236 | * Although it is not obvious whether or not NFS clients really care if |
233 | * a returned error value is in the specified list for the procedure, the | | 237 | * a returned error value is in the specified list for the procedure, the |
234 | * safest thing to do is filter them appropriately. For Version 2, the | | 238 | * safest thing to do is filter them appropriately. For Version 2, the |
235 | * X/Open XNFS document is the only specification that defines error values | | 239 | * X/Open XNFS document is the only specification that defines error values |
236 | * for each RPC (The RFC simply lists all possible error values for all RPCs), | | 240 | * for each RPC (The RFC simply lists all possible error values for all RPCs), |
237 | * so I have decided to not do this for Version 2. | | 241 | * so I have decided to not do this for Version 2. |
238 | * The first entry is the default error return and the rest are the valid | | 242 | * The first entry is the default error return and the rest are the valid |
239 | * errors for that RPC in increasing numeric order. | | 243 | * errors for that RPC in increasing numeric order. |
240 | */ | | 244 | */ |
241 | static const short nfsv3err_null[] = { | | 245 | static const short nfsv3err_null[] = { |
242 | 0, | | 246 | 0, |
243 | 0, | | 247 | 0, |
244 | }; | | 248 | }; |
245 | | | 249 | |
246 | static const short nfsv3err_getattr[] = { | | 250 | static const short nfsv3err_getattr[] = { |
247 | NFSERR_IO, | | 251 | NFSERR_IO, |
248 | NFSERR_IO, | | 252 | NFSERR_IO, |
249 | NFSERR_STALE, | | 253 | NFSERR_STALE, |
250 | NFSERR_BADHANDLE, | | 254 | NFSERR_BADHANDLE, |
251 | NFSERR_SERVERFAULT, | | 255 | NFSERR_SERVERFAULT, |
252 | 0, | | 256 | 0, |
253 | }; | | 257 | }; |
254 | | | 258 | |
255 | static const short nfsv3err_setattr[] = { | | 259 | static const short nfsv3err_setattr[] = { |
256 | NFSERR_IO, | | 260 | NFSERR_IO, |
257 | NFSERR_PERM, | | 261 | NFSERR_PERM, |
258 | NFSERR_IO, | | 262 | NFSERR_IO, |
259 | NFSERR_ACCES, | | 263 | NFSERR_ACCES, |
260 | NFSERR_INVAL, | | 264 | NFSERR_INVAL, |
261 | NFSERR_NOSPC, | | 265 | NFSERR_NOSPC, |
262 | NFSERR_ROFS, | | 266 | NFSERR_ROFS, |
263 | NFSERR_DQUOT, | | 267 | NFSERR_DQUOT, |
264 | NFSERR_STALE, | | 268 | NFSERR_STALE, |
265 | NFSERR_BADHANDLE, | | 269 | NFSERR_BADHANDLE, |
266 | NFSERR_NOT_SYNC, | | 270 | NFSERR_NOT_SYNC, |
267 | NFSERR_SERVERFAULT, | | 271 | NFSERR_SERVERFAULT, |
268 | 0, | | 272 | 0, |
269 | }; | | 273 | }; |
270 | | | 274 | |
271 | static const short nfsv3err_lookup[] = { | | 275 | static const short nfsv3err_lookup[] = { |
272 | NFSERR_IO, | | 276 | NFSERR_IO, |
273 | NFSERR_NOENT, | | 277 | NFSERR_NOENT, |
274 | NFSERR_IO, | | 278 | NFSERR_IO, |
275 | NFSERR_ACCES, | | 279 | NFSERR_ACCES, |
276 | NFSERR_NOTDIR, | | 280 | NFSERR_NOTDIR, |
277 | NFSERR_NAMETOL, | | 281 | NFSERR_NAMETOL, |
278 | NFSERR_STALE, | | 282 | NFSERR_STALE, |
279 | NFSERR_BADHANDLE, | | 283 | NFSERR_BADHANDLE, |
280 | NFSERR_SERVERFAULT, | | 284 | NFSERR_SERVERFAULT, |
281 | 0, | | 285 | 0, |
282 | }; | | 286 | }; |
283 | | | 287 | |
284 | static const short nfsv3err_access[] = { | | 288 | static const short nfsv3err_access[] = { |
285 | NFSERR_IO, | | 289 | NFSERR_IO, |
286 | NFSERR_IO, | | 290 | NFSERR_IO, |
287 | NFSERR_STALE, | | 291 | NFSERR_STALE, |
288 | NFSERR_BADHANDLE, | | 292 | NFSERR_BADHANDLE, |
289 | NFSERR_SERVERFAULT, | | 293 | NFSERR_SERVERFAULT, |
290 | 0, | | 294 | 0, |
291 | }; | | 295 | }; |
292 | | | 296 | |
293 | static const short nfsv3err_readlink[] = { | | 297 | static const short nfsv3err_readlink[] = { |
294 | NFSERR_IO, | | 298 | NFSERR_IO, |
295 | NFSERR_IO, | | 299 | NFSERR_IO, |
296 | NFSERR_ACCES, | | 300 | NFSERR_ACCES, |
297 | NFSERR_INVAL, | | 301 | NFSERR_INVAL, |
298 | NFSERR_STALE, | | 302 | NFSERR_STALE, |
299 | NFSERR_BADHANDLE, | | 303 | NFSERR_BADHANDLE, |
300 | NFSERR_NOTSUPP, | | 304 | NFSERR_NOTSUPP, |
301 | NFSERR_SERVERFAULT, | | 305 | NFSERR_SERVERFAULT, |
302 | 0, | | 306 | 0, |
303 | }; | | 307 | }; |
304 | | | 308 | |
305 | static const short nfsv3err_read[] = { | | 309 | static const short nfsv3err_read[] = { |
306 | NFSERR_IO, | | 310 | NFSERR_IO, |
307 | NFSERR_IO, | | 311 | NFSERR_IO, |
308 | NFSERR_NXIO, | | 312 | NFSERR_NXIO, |
309 | NFSERR_ACCES, | | 313 | NFSERR_ACCES, |
310 | NFSERR_INVAL, | | 314 | NFSERR_INVAL, |
311 | NFSERR_STALE, | | 315 | NFSERR_STALE, |
312 | NFSERR_BADHANDLE, | | 316 | NFSERR_BADHANDLE, |
313 | NFSERR_SERVERFAULT, | | 317 | NFSERR_SERVERFAULT, |
314 | NFSERR_JUKEBOX, | | 318 | NFSERR_JUKEBOX, |
315 | 0, | | 319 | 0, |
316 | }; | | 320 | }; |
317 | | | 321 | |
318 | static const short nfsv3err_write[] = { | | 322 | static const short nfsv3err_write[] = { |
319 | NFSERR_IO, | | 323 | NFSERR_IO, |
320 | NFSERR_IO, | | 324 | NFSERR_IO, |
321 | NFSERR_ACCES, | | 325 | NFSERR_ACCES, |
322 | NFSERR_INVAL, | | 326 | NFSERR_INVAL, |
323 | NFSERR_FBIG, | | 327 | NFSERR_FBIG, |
324 | NFSERR_NOSPC, | | 328 | NFSERR_NOSPC, |
325 | NFSERR_ROFS, | | 329 | NFSERR_ROFS, |
326 | NFSERR_DQUOT, | | 330 | NFSERR_DQUOT, |
327 | NFSERR_STALE, | | 331 | NFSERR_STALE, |
328 | NFSERR_BADHANDLE, | | 332 | NFSERR_BADHANDLE, |
329 | NFSERR_SERVERFAULT, | | 333 | NFSERR_SERVERFAULT, |
330 | NFSERR_JUKEBOX, | | 334 | NFSERR_JUKEBOX, |
331 | 0, | | 335 | 0, |
332 | }; | | 336 | }; |
333 | | | 337 | |
334 | static const short nfsv3err_create[] = { | | 338 | static const short nfsv3err_create[] = { |
335 | NFSERR_IO, | | 339 | NFSERR_IO, |
336 | NFSERR_IO, | | 340 | NFSERR_IO, |
337 | NFSERR_ACCES, | | 341 | NFSERR_ACCES, |
338 | NFSERR_EXIST, | | 342 | NFSERR_EXIST, |
339 | NFSERR_NOTDIR, | | 343 | NFSERR_NOTDIR, |
340 | NFSERR_NOSPC, | | 344 | NFSERR_NOSPC, |
341 | NFSERR_ROFS, | | 345 | NFSERR_ROFS, |
342 | NFSERR_NAMETOL, | | 346 | NFSERR_NAMETOL, |
343 | NFSERR_DQUOT, | | 347 | NFSERR_DQUOT, |
344 | NFSERR_STALE, | | 348 | NFSERR_STALE, |
345 | NFSERR_BADHANDLE, | | 349 | NFSERR_BADHANDLE, |
346 | NFSERR_NOTSUPP, | | 350 | NFSERR_NOTSUPP, |
347 | NFSERR_SERVERFAULT, | | 351 | NFSERR_SERVERFAULT, |
348 | 0, | | 352 | 0, |
349 | }; | | 353 | }; |
350 | | | 354 | |
351 | static const short nfsv3err_mkdir[] = { | | 355 | static const short nfsv3err_mkdir[] = { |
352 | NFSERR_IO, | | 356 | NFSERR_IO, |
353 | NFSERR_IO, | | 357 | NFSERR_IO, |
354 | NFSERR_ACCES, | | 358 | NFSERR_ACCES, |
355 | NFSERR_EXIST, | | 359 | NFSERR_EXIST, |
356 | NFSERR_NOTDIR, | | 360 | NFSERR_NOTDIR, |
357 | NFSERR_NOSPC, | | 361 | NFSERR_NOSPC, |
358 | NFSERR_ROFS, | | 362 | NFSERR_ROFS, |
359 | NFSERR_NAMETOL, | | 363 | NFSERR_NAMETOL, |
360 | NFSERR_DQUOT, | | 364 | NFSERR_DQUOT, |
361 | NFSERR_STALE, | | 365 | NFSERR_STALE, |
362 | NFSERR_BADHANDLE, | | 366 | NFSERR_BADHANDLE, |
363 | NFSERR_NOTSUPP, | | 367 | NFSERR_NOTSUPP, |
364 | NFSERR_SERVERFAULT, | | 368 | NFSERR_SERVERFAULT, |
365 | 0, | | 369 | 0, |
366 | }; | | 370 | }; |
367 | | | 371 | |
368 | static const short nfsv3err_symlink[] = { | | 372 | static const short nfsv3err_symlink[] = { |
369 | NFSERR_IO, | | 373 | NFSERR_IO, |
370 | NFSERR_IO, | | 374 | NFSERR_IO, |
371 | NFSERR_ACCES, | | 375 | NFSERR_ACCES, |
372 | NFSERR_EXIST, | | 376 | NFSERR_EXIST, |
373 | NFSERR_NOTDIR, | | 377 | NFSERR_NOTDIR, |
374 | NFSERR_NOSPC, | | 378 | NFSERR_NOSPC, |
375 | NFSERR_ROFS, | | 379 | NFSERR_ROFS, |
376 | NFSERR_NAMETOL, | | 380 | NFSERR_NAMETOL, |
377 | NFSERR_DQUOT, | | 381 | NFSERR_DQUOT, |
378 | NFSERR_STALE, | | 382 | NFSERR_STALE, |
379 | NFSERR_BADHANDLE, | | 383 | NFSERR_BADHANDLE, |
380 | NFSERR_NOTSUPP, | | 384 | NFSERR_NOTSUPP, |
381 | NFSERR_SERVERFAULT, | | 385 | NFSERR_SERVERFAULT, |
382 | 0, | | 386 | 0, |
383 | }; | | 387 | }; |
384 | | | 388 | |
385 | static const short nfsv3err_mknod[] = { | | 389 | static const short nfsv3err_mknod[] = { |
386 | NFSERR_IO, | | 390 | NFSERR_IO, |
387 | NFSERR_IO, | | 391 | NFSERR_IO, |
388 | NFSERR_ACCES, | | 392 | NFSERR_ACCES, |
389 | NFSERR_EXIST, | | 393 | NFSERR_EXIST, |
390 | NFSERR_NOTDIR, | | 394 | NFSERR_NOTDIR, |
391 | NFSERR_NOSPC, | | 395 | NFSERR_NOSPC, |
392 | NFSERR_ROFS, | | 396 | NFSERR_ROFS, |
393 | NFSERR_NAMETOL, | | 397 | NFSERR_NAMETOL, |
394 | NFSERR_DQUOT, | | 398 | NFSERR_DQUOT, |
395 | NFSERR_STALE, | | 399 | NFSERR_STALE, |
396 | NFSERR_BADHANDLE, | | 400 | NFSERR_BADHANDLE, |
397 | NFSERR_NOTSUPP, | | 401 | NFSERR_NOTSUPP, |
398 | NFSERR_SERVERFAULT, | | 402 | NFSERR_SERVERFAULT, |
399 | NFSERR_BADTYPE, | | 403 | NFSERR_BADTYPE, |
400 | 0, | | 404 | 0, |
401 | }; | | 405 | }; |
402 | | | 406 | |
403 | static const short nfsv3err_remove[] = { | | 407 | static const short nfsv3err_remove[] = { |
404 | NFSERR_IO, | | 408 | NFSERR_IO, |
405 | NFSERR_NOENT, | | 409 | NFSERR_NOENT, |
406 | NFSERR_IO, | | 410 | NFSERR_IO, |
407 | NFSERR_ACCES, | | 411 | NFSERR_ACCES, |
408 | NFSERR_NOTDIR, | | 412 | NFSERR_NOTDIR, |
409 | NFSERR_ROFS, | | 413 | NFSERR_ROFS, |
410 | NFSERR_NAMETOL, | | 414 | NFSERR_NAMETOL, |
411 | NFSERR_STALE, | | 415 | NFSERR_STALE, |
412 | NFSERR_BADHANDLE, | | 416 | NFSERR_BADHANDLE, |
413 | NFSERR_SERVERFAULT, | | 417 | NFSERR_SERVERFAULT, |
414 | 0, | | 418 | 0, |
415 | }; | | 419 | }; |
416 | | | 420 | |
417 | static const short nfsv3err_rmdir[] = { | | 421 | static const short nfsv3err_rmdir[] = { |
418 | NFSERR_IO, | | 422 | NFSERR_IO, |
419 | NFSERR_NOENT, | | 423 | NFSERR_NOENT, |
420 | NFSERR_IO, | | 424 | NFSERR_IO, |
421 | NFSERR_ACCES, | | 425 | NFSERR_ACCES, |
422 | NFSERR_EXIST, | | 426 | NFSERR_EXIST, |
423 | NFSERR_NOTDIR, | | 427 | NFSERR_NOTDIR, |
424 | NFSERR_INVAL, | | 428 | NFSERR_INVAL, |
425 | NFSERR_ROFS, | | 429 | NFSERR_ROFS, |
426 | NFSERR_NAMETOL, | | 430 | NFSERR_NAMETOL, |
427 | NFSERR_NOTEMPTY, | | 431 | NFSERR_NOTEMPTY, |
428 | NFSERR_STALE, | | 432 | NFSERR_STALE, |
429 | NFSERR_BADHANDLE, | | 433 | NFSERR_BADHANDLE, |
430 | NFSERR_NOTSUPP, | | 434 | NFSERR_NOTSUPP, |
431 | NFSERR_SERVERFAULT, | | 435 | NFSERR_SERVERFAULT, |
432 | 0, | | 436 | 0, |
433 | }; | | 437 | }; |
434 | | | 438 | |
435 | static const short nfsv3err_rename[] = { | | 439 | static const short nfsv3err_rename[] = { |
436 | NFSERR_IO, | | 440 | NFSERR_IO, |
437 | NFSERR_NOENT, | | 441 | NFSERR_NOENT, |
438 | NFSERR_IO, | | 442 | NFSERR_IO, |
439 | NFSERR_ACCES, | | 443 | NFSERR_ACCES, |
440 | NFSERR_EXIST, | | 444 | NFSERR_EXIST, |
441 | NFSERR_XDEV, | | 445 | NFSERR_XDEV, |
442 | NFSERR_NOTDIR, | | 446 | NFSERR_NOTDIR, |
443 | NFSERR_ISDIR, | | 447 | NFSERR_ISDIR, |
444 | NFSERR_INVAL, | | 448 | NFSERR_INVAL, |
445 | NFSERR_NOSPC, | | 449 | NFSERR_NOSPC, |
446 | NFSERR_ROFS, | | 450 | NFSERR_ROFS, |
447 | NFSERR_MLINK, | | 451 | NFSERR_MLINK, |
448 | NFSERR_NAMETOL, | | 452 | NFSERR_NAMETOL, |
449 | NFSERR_NOTEMPTY, | | 453 | NFSERR_NOTEMPTY, |
450 | NFSERR_DQUOT, | | 454 | NFSERR_DQUOT, |
451 | NFSERR_STALE, | | 455 | NFSERR_STALE, |
452 | NFSERR_BADHANDLE, | | 456 | NFSERR_BADHANDLE, |
453 | NFSERR_NOTSUPP, | | 457 | NFSERR_NOTSUPP, |
454 | NFSERR_SERVERFAULT, | | 458 | NFSERR_SERVERFAULT, |
455 | 0, | | 459 | 0, |
456 | }; | | 460 | }; |
457 | | | 461 | |
458 | static const short nfsv3err_link[] = { | | 462 | static const short nfsv3err_link[] = { |
459 | NFSERR_IO, | | 463 | NFSERR_IO, |
460 | NFSERR_IO, | | 464 | NFSERR_IO, |
461 | NFSERR_ACCES, | | 465 | NFSERR_ACCES, |
462 | NFSERR_EXIST, | | 466 | NFSERR_EXIST, |
463 | NFSERR_XDEV, | | 467 | NFSERR_XDEV, |
464 | NFSERR_NOTDIR, | | 468 | NFSERR_NOTDIR, |
465 | NFSERR_INVAL, | | 469 | NFSERR_INVAL, |
466 | NFSERR_NOSPC, | | 470 | NFSERR_NOSPC, |
467 | NFSERR_ROFS, | | 471 | NFSERR_ROFS, |
468 | NFSERR_MLINK, | | 472 | NFSERR_MLINK, |
469 | NFSERR_NAMETOL, | | 473 | NFSERR_NAMETOL, |
470 | NFSERR_DQUOT, | | 474 | NFSERR_DQUOT, |
471 | NFSERR_STALE, | | 475 | NFSERR_STALE, |
472 | NFSERR_BADHANDLE, | | 476 | NFSERR_BADHANDLE, |
473 | NFSERR_NOTSUPP, | | 477 | NFSERR_NOTSUPP, |
474 | NFSERR_SERVERFAULT, | | 478 | NFSERR_SERVERFAULT, |
475 | 0, | | 479 | 0, |
476 | }; | | 480 | }; |
477 | | | 481 | |
478 | static const short nfsv3err_readdir[] = { | | 482 | static const short nfsv3err_readdir[] = { |
479 | NFSERR_IO, | | 483 | NFSERR_IO, |
480 | NFSERR_IO, | | 484 | NFSERR_IO, |
481 | NFSERR_ACCES, | | 485 | NFSERR_ACCES, |
482 | NFSERR_NOTDIR, | | 486 | NFSERR_NOTDIR, |
483 | NFSERR_STALE, | | 487 | NFSERR_STALE, |
484 | NFSERR_BADHANDLE, | | 488 | NFSERR_BADHANDLE, |
485 | NFSERR_BAD_COOKIE, | | 489 | NFSERR_BAD_COOKIE, |
486 | NFSERR_TOOSMALL, | | 490 | NFSERR_TOOSMALL, |
487 | NFSERR_SERVERFAULT, | | 491 | NFSERR_SERVERFAULT, |
488 | 0, | | 492 | 0, |
489 | }; | | 493 | }; |
490 | | | 494 | |
491 | static const short nfsv3err_readdirplus[] = { | | 495 | static const short nfsv3err_readdirplus[] = { |
492 | NFSERR_IO, | | 496 | NFSERR_IO, |
493 | NFSERR_IO, | | 497 | NFSERR_IO, |
494 | NFSERR_ACCES, | | 498 | NFSERR_ACCES, |
495 | NFSERR_NOTDIR, | | 499 | NFSERR_NOTDIR, |
496 | NFSERR_STALE, | | 500 | NFSERR_STALE, |
497 | NFSERR_BADHANDLE, | | 501 | NFSERR_BADHANDLE, |
498 | NFSERR_BAD_COOKIE, | | 502 | NFSERR_BAD_COOKIE, |
499 | NFSERR_NOTSUPP, | | 503 | NFSERR_NOTSUPP, |
500 | NFSERR_TOOSMALL, | | 504 | NFSERR_TOOSMALL, |
501 | NFSERR_SERVERFAULT, | | 505 | NFSERR_SERVERFAULT, |
502 | 0, | | 506 | 0, |
503 | }; | | 507 | }; |
504 | | | 508 | |
505 | static const short nfsv3err_fsstat[] = { | | 509 | static const short nfsv3err_fsstat[] = { |
506 | NFSERR_IO, | | 510 | NFSERR_IO, |
507 | NFSERR_IO, | | 511 | NFSERR_IO, |
508 | NFSERR_STALE, | | 512 | NFSERR_STALE, |
509 | NFSERR_BADHANDLE, | | 513 | NFSERR_BADHANDLE, |
510 | NFSERR_SERVERFAULT, | | 514 | NFSERR_SERVERFAULT, |
511 | 0, | | 515 | 0, |
512 | }; | | 516 | }; |
513 | | | 517 | |
514 | static const short nfsv3err_fsinfo[] = { | | 518 | static const short nfsv3err_fsinfo[] = { |
515 | NFSERR_STALE, | | 519 | NFSERR_STALE, |
516 | NFSERR_STALE, | | 520 | NFSERR_STALE, |
517 | NFSERR_BADHANDLE, | | 521 | NFSERR_BADHANDLE, |
518 | NFSERR_SERVERFAULT, | | 522 | NFSERR_SERVERFAULT, |
519 | 0, | | 523 | 0, |
520 | }; | | 524 | }; |
521 | | | 525 | |
522 | static const short nfsv3err_pathconf[] = { | | 526 | static const short nfsv3err_pathconf[] = { |
523 | NFSERR_STALE, | | 527 | NFSERR_STALE, |
524 | NFSERR_STALE, | | 528 | NFSERR_STALE, |
525 | NFSERR_BADHANDLE, | | 529 | NFSERR_BADHANDLE, |
526 | NFSERR_SERVERFAULT, | | 530 | NFSERR_SERVERFAULT, |
527 | 0, | | 531 | 0, |
528 | }; | | 532 | }; |
529 | | | 533 | |
530 | static const short nfsv3err_commit[] = { | | 534 | static const short nfsv3err_commit[] = { |
531 | NFSERR_IO, | | 535 | NFSERR_IO, |
532 | NFSERR_IO, | | 536 | NFSERR_IO, |
533 | NFSERR_STALE, | | 537 | NFSERR_STALE, |
534 | NFSERR_BADHANDLE, | | 538 | NFSERR_BADHANDLE, |
535 | NFSERR_SERVERFAULT, | | 539 | NFSERR_SERVERFAULT, |
536 | 0, | | 540 | 0, |
537 | }; | | 541 | }; |
538 | | | 542 | |
539 | static const short * const nfsrv_v3errmap[] = { | | 543 | static const short * const nfsrv_v3errmap[] = { |
540 | nfsv3err_null, | | 544 | nfsv3err_null, |
541 | nfsv3err_getattr, | | 545 | nfsv3err_getattr, |
542 | nfsv3err_setattr, | | 546 | nfsv3err_setattr, |
543 | nfsv3err_lookup, | | 547 | nfsv3err_lookup, |
544 | nfsv3err_access, | | 548 | nfsv3err_access, |
545 | nfsv3err_readlink, | | 549 | nfsv3err_readlink, |
546 | nfsv3err_read, | | 550 | nfsv3err_read, |
547 | nfsv3err_write, | | 551 | nfsv3err_write, |
548 | nfsv3err_create, | | 552 | nfsv3err_create, |
549 | nfsv3err_mkdir, | | 553 | nfsv3err_mkdir, |
550 | nfsv3err_symlink, | | 554 | nfsv3err_symlink, |
551 | nfsv3err_mknod, | | 555 | nfsv3err_mknod, |
552 | nfsv3err_remove, | | 556 | nfsv3err_remove, |
553 | nfsv3err_rmdir, | | 557 | nfsv3err_rmdir, |
554 | nfsv3err_rename, | | 558 | nfsv3err_rename, |
555 | nfsv3err_link, | | 559 | nfsv3err_link, |
556 | nfsv3err_readdir, | | 560 | nfsv3err_readdir, |
557 | nfsv3err_readdirplus, | | 561 | nfsv3err_readdirplus, |
558 | nfsv3err_fsstat, | | 562 | nfsv3err_fsstat, |
559 | nfsv3err_fsinfo, | | 563 | nfsv3err_fsinfo, |
560 | nfsv3err_pathconf, | | 564 | nfsv3err_pathconf, |
561 | nfsv3err_commit, | | 565 | nfsv3err_commit, |
562 | }; | | 566 | }; |
563 | | | 567 | |
564 | extern struct nfsrtt nfsrtt; | | 568 | extern struct nfsrtt nfsrtt; |
565 | | | 569 | |
566 | u_long nfsdirhashmask; | | 570 | u_long nfsdirhashmask; |
567 | | | 571 | |
568 | int nfs_webnamei(struct nameidata *, struct vnode *, struct proc *); | | 572 | int nfs_webnamei(struct nameidata *, struct vnode *, struct proc *); |
569 | | | 573 | |
570 | /* | | 574 | /* |
571 | * Create the header for an rpc request packet | | 575 | * Create the header for an rpc request packet |
572 | * The hsiz is the size of the rest of the nfs request header. | | 576 | * The hsiz is the size of the rest of the nfs request header. |
573 | * (just used to decide if a cluster is a good idea) | | 577 | * (just used to decide if a cluster is a good idea) |
574 | */ | | 578 | */ |
575 | struct mbuf * | | 579 | struct mbuf * |
576 | nfsm_reqh(struct nfsnode *np, u_long procid, int hsiz, char **bposp) | | 580 | nfsm_reqh(struct nfsnode *np, u_long procid, int hsiz, char **bposp) |
577 | { | | 581 | { |
578 | struct mbuf *mb; | | 582 | struct mbuf *mb; |
579 | char *bpos; | | 583 | char *bpos; |
580 | | | 584 | |
581 | mb = m_get(M_WAIT, MT_DATA); | | 585 | mb = m_get(M_WAIT, MT_DATA); |
582 | MCLAIM(mb, &nfs_mowner); | | 586 | MCLAIM(mb, &nfs_mowner); |
583 | if (hsiz >= MINCLSIZE) | | 587 | if (hsiz >= MINCLSIZE) |
584 | m_clget(mb, M_WAIT); | | 588 | m_clget(mb, M_WAIT); |
585 | mb->m_len = 0; | | 589 | mb->m_len = 0; |
586 | bpos = mtod(mb, void *); | | 590 | bpos = mtod(mb, void *); |
587 | | | 591 | |
588 | /* Finally, return values */ | | 592 | /* Finally, return values */ |
589 | *bposp = bpos; | | 593 | *bposp = bpos; |
590 | return (mb); | | 594 | return (mb); |
591 | } | | 595 | } |
592 | | | 596 | |
593 | /* | | 597 | /* |
594 | * Build the RPC header and fill in the authorization info. | | 598 | * Build the RPC header and fill in the authorization info. |
595 | * The authorization string argument is only used when the credentials | | 599 | * The authorization string argument is only used when the credentials |
596 | * come from outside of the kernel. | | 600 | * come from outside of the kernel. |
597 | * Returns the head of the mbuf list. | | 601 | * Returns the head of the mbuf list. |
598 | */ | | 602 | */ |
599 | struct mbuf * | | 603 | struct mbuf * |
600 | nfsm_rpchead(kauth_cred_t cr, int nmflag, int procid, | | 604 | nfsm_rpchead(kauth_cred_t cr, int nmflag, int procid, |
601 | int auth_type, int auth_len, char *auth_str, int verf_len, | | 605 | int auth_type, int auth_len, char *auth_str, int verf_len, |
602 | char *verf_str, struct mbuf *mrest, int mrest_len, | | 606 | char *verf_str, struct mbuf *mrest, int mrest_len, |
603 | struct mbuf **mbp, uint32_t *xidp) | | 607 | struct mbuf **mbp, uint32_t *xidp) |
604 | { | | 608 | { |
605 | struct mbuf *mb; | | 609 | struct mbuf *mb; |
606 | u_int32_t *tl; | | 610 | u_int32_t *tl; |
607 | char *bpos; | | 611 | char *bpos; |
608 | int i; | | 612 | int i; |
609 | struct mbuf *mreq; | | 613 | struct mbuf *mreq; |
610 | int siz, grpsiz, authsiz; | | 614 | int siz, grpsiz, authsiz; |
611 | | | 615 | |
612 | authsiz = nfsm_rndup(auth_len); | | 616 | authsiz = nfsm_rndup(auth_len); |
613 | mb = m_gethdr(M_WAIT, MT_DATA); | | 617 | mb = m_gethdr(M_WAIT, MT_DATA); |
614 | MCLAIM(mb, &nfs_mowner); | | 618 | MCLAIM(mb, &nfs_mowner); |
615 | if ((authsiz + 10 * NFSX_UNSIGNED) >= MINCLSIZE) { | | 619 | if ((authsiz + 10 * NFSX_UNSIGNED) >= MINCLSIZE) { |
616 | m_clget(mb, M_WAIT); | | 620 | m_clget(mb, M_WAIT); |
617 | } else if ((authsiz + 10 * NFSX_UNSIGNED) < MHLEN) { | | 621 | } else if ((authsiz + 10 * NFSX_UNSIGNED) < MHLEN) { |
618 | m_align(mb, authsiz + 10 * NFSX_UNSIGNED); | | 622 | m_align(mb, authsiz + 10 * NFSX_UNSIGNED); |
619 | } else { | | 623 | } else { |
620 | m_align(mb, 8 * NFSX_UNSIGNED); | | 624 | m_align(mb, 8 * NFSX_UNSIGNED); |
621 | } | | 625 | } |
622 | mb->m_len = 0; | | 626 | mb->m_len = 0; |
623 | mreq = mb; | | 627 | mreq = mb; |
624 | bpos = mtod(mb, void *); | | 628 | bpos = mtod(mb, void *); |
625 | | | 629 | |
626 | /* | | 630 | /* |
627 | * First the RPC header. | | 631 | * First the RPC header. |
628 | */ | | 632 | */ |
629 | nfsm_build(tl, u_int32_t *, 8 * NFSX_UNSIGNED); | | 633 | nfsm_build(tl, u_int32_t *, 8 * NFSX_UNSIGNED); |
630 | | | 634 | |
631 | *tl++ = *xidp = nfs_getxid(); | | 635 | *tl++ = *xidp = nfs_getxid(); |
632 | *tl++ = rpc_call; | | 636 | *tl++ = rpc_call; |
633 | *tl++ = rpc_vers; | | 637 | *tl++ = rpc_vers; |
634 | *tl++ = txdr_unsigned(NFS_PROG); | | 638 | *tl++ = txdr_unsigned(NFS_PROG); |
635 | if (nmflag & NFSMNT_NFSV3) | | 639 | if (nmflag & NFSMNT_NFSV3) |
636 | *tl++ = txdr_unsigned(NFS_VER3); | | 640 | *tl++ = txdr_unsigned(NFS_VER3); |
637 | else | | 641 | else |
638 | *tl++ = txdr_unsigned(NFS_VER2); | | 642 | *tl++ = txdr_unsigned(NFS_VER2); |
639 | if (nmflag & NFSMNT_NFSV3) | | 643 | if (nmflag & NFSMNT_NFSV3) |
640 | *tl++ = txdr_unsigned(procid); | | 644 | *tl++ = txdr_unsigned(procid); |
641 | else | | 645 | else |
642 | *tl++ = txdr_unsigned(nfsv2_procid[procid]); | | 646 | *tl++ = txdr_unsigned(nfsv2_procid[procid]); |
643 | | | 647 | |
644 | /* | | 648 | /* |
645 | * And then the authorization cred. | | 649 | * And then the authorization cred. |
646 | */ | | 650 | */ |
647 | *tl++ = txdr_unsigned(auth_type); | | 651 | *tl++ = txdr_unsigned(auth_type); |
648 | *tl = txdr_unsigned(authsiz); | | 652 | *tl = txdr_unsigned(authsiz); |
649 | switch (auth_type) { | | 653 | switch (auth_type) { |
650 | case RPCAUTH_UNIX: | | 654 | case RPCAUTH_UNIX: |
651 | nfsm_build(tl, u_int32_t *, auth_len); | | 655 | nfsm_build(tl, u_int32_t *, auth_len); |
652 | *tl++ = 0; /* stamp ?? */ | | 656 | *tl++ = 0; /* stamp ?? */ |
653 | *tl++ = 0; /* NULL hostname */ | | 657 | *tl++ = 0; /* NULL hostname */ |
654 | *tl++ = txdr_unsigned(kauth_cred_geteuid(cr)); | | 658 | *tl++ = txdr_unsigned(kauth_cred_geteuid(cr)); |
655 | *tl++ = txdr_unsigned(kauth_cred_getegid(cr)); | | 659 | *tl++ = txdr_unsigned(kauth_cred_getegid(cr)); |
656 | grpsiz = (auth_len >> 2) - 5; | | 660 | grpsiz = (auth_len >> 2) - 5; |
657 | *tl++ = txdr_unsigned(grpsiz); | | 661 | *tl++ = txdr_unsigned(grpsiz); |
658 | for (i = 0; i < grpsiz; i++) | | 662 | for (i = 0; i < grpsiz; i++) |
659 | *tl++ = txdr_unsigned(kauth_cred_group(cr, i)); /* XXX elad review */ | | 663 | *tl++ = txdr_unsigned(kauth_cred_group(cr, i)); /* XXX elad review */ |
660 | break; | | 664 | break; |
661 | case RPCAUTH_KERB4: | | 665 | case RPCAUTH_KERB4: |
662 | siz = auth_len; | | 666 | siz = auth_len; |
663 | while (siz > 0) { | | 667 | while (siz > 0) { |
664 | if (M_TRAILINGSPACE(mb) == 0) { | | 668 | if (M_TRAILINGSPACE(mb) == 0) { |
665 | struct mbuf *mb2; | | 669 | struct mbuf *mb2; |
666 | mb2 = m_get(M_WAIT, MT_DATA); | | 670 | mb2 = m_get(M_WAIT, MT_DATA); |
667 | MCLAIM(mb2, &nfs_mowner); | | 671 | MCLAIM(mb2, &nfs_mowner); |
668 | if (siz >= MINCLSIZE) | | 672 | if (siz >= MINCLSIZE) |
669 | m_clget(mb2, M_WAIT); | | 673 | m_clget(mb2, M_WAIT); |
670 | mb->m_next = mb2; | | 674 | mb->m_next = mb2; |
671 | mb = mb2; | | 675 | mb = mb2; |
672 | mb->m_len = 0; | | 676 | mb->m_len = 0; |
673 | bpos = mtod(mb, void *); | | 677 | bpos = mtod(mb, void *); |
674 | } | | 678 | } |
675 | i = uimin(siz, M_TRAILINGSPACE(mb)); | | 679 | i = uimin(siz, M_TRAILINGSPACE(mb)); |
676 | memcpy(bpos, auth_str, i); | | 680 | memcpy(bpos, auth_str, i); |
677 | mb->m_len += i; | | 681 | mb->m_len += i; |
678 | auth_str += i; | | 682 | auth_str += i; |
679 | bpos += i; | | 683 | bpos += i; |
680 | siz -= i; | | 684 | siz -= i; |
681 | } | | 685 | } |
682 | if ((siz = (nfsm_rndup(auth_len) - auth_len)) > 0) { | | 686 | if ((siz = (nfsm_rndup(auth_len) - auth_len)) > 0) { |
683 | for (i = 0; i < siz; i++) | | 687 | for (i = 0; i < siz; i++) |
684 | *bpos++ = '\0'; | | 688 | *bpos++ = '\0'; |
685 | mb->m_len += siz; | | 689 | mb->m_len += siz; |
686 | } | | 690 | } |
687 | break; | | 691 | break; |
688 | }; | | 692 | }; |
689 | | | 693 | |
690 | /* | | 694 | /* |
691 | * And the verifier... | | 695 | * And the verifier... |
692 | */ | | 696 | */ |
693 | nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); | | 697 | nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); |
694 | if (verf_str) { | | 698 | if (verf_str) { |
695 | *tl++ = txdr_unsigned(RPCAUTH_KERB4); | | 699 | *tl++ = txdr_unsigned(RPCAUTH_KERB4); |
696 | *tl = txdr_unsigned(verf_len); | | 700 | *tl = txdr_unsigned(verf_len); |
697 | siz = verf_len; | | 701 | siz = verf_len; |
698 | while (siz > 0) { | | 702 | while (siz > 0) { |
699 | if (M_TRAILINGSPACE(mb) == 0) { | | 703 | if (M_TRAILINGSPACE(mb) == 0) { |
700 | struct mbuf *mb2; | | 704 | struct mbuf *mb2; |
701 | mb2 = m_get(M_WAIT, MT_DATA); | | 705 | mb2 = m_get(M_WAIT, MT_DATA); |
702 | MCLAIM(mb2, &nfs_mowner); | | 706 | MCLAIM(mb2, &nfs_mowner); |
703 | if (siz >= MINCLSIZE) | | 707 | if (siz >= MINCLSIZE) |
704 | m_clget(mb2, M_WAIT); | | 708 | m_clget(mb2, M_WAIT); |
705 | mb->m_next = mb2; | | 709 | mb->m_next = mb2; |
706 | mb = mb2; | | 710 | mb = mb2; |
707 | mb->m_len = 0; | | 711 | mb->m_len = 0; |
708 | bpos = mtod(mb, void *); | | 712 | bpos = mtod(mb, void *); |
709 | } | | 713 | } |
710 | i = uimin(siz, M_TRAILINGSPACE(mb)); | | 714 | i = uimin(siz, M_TRAILINGSPACE(mb)); |
711 | memcpy(bpos, verf_str, i); | | 715 | memcpy(bpos, verf_str, i); |
712 | mb->m_len += i; | | 716 | mb->m_len += i; |
713 | verf_str += i; | | 717 | verf_str += i; |
714 | bpos += i; | | 718 | bpos += i; |
715 | siz -= i; | | 719 | siz -= i; |
716 | } | | 720 | } |
717 | if ((siz = (nfsm_rndup(verf_len) - verf_len)) > 0) { | | 721 | if ((siz = (nfsm_rndup(verf_len) - verf_len)) > 0) { |
718 | for (i = 0; i < siz; i++) | | 722 | for (i = 0; i < siz; i++) |
719 | *bpos++ = '\0'; | | 723 | *bpos++ = '\0'; |
720 | mb->m_len += siz; | | 724 | mb->m_len += siz; |
721 | } | | 725 | } |
722 | } else { | | 726 | } else { |
723 | *tl++ = txdr_unsigned(RPCAUTH_NULL); | | 727 | *tl++ = txdr_unsigned(RPCAUTH_NULL); |
724 | *tl = 0; | | 728 | *tl = 0; |
725 | } | | 729 | } |
726 | mb->m_next = mrest; | | 730 | mb->m_next = mrest; |
727 | mreq->m_pkthdr.len = authsiz + 10 * NFSX_UNSIGNED + mrest_len; | | 731 | mreq->m_pkthdr.len = authsiz + 10 * NFSX_UNSIGNED + mrest_len; |
728 | m_reset_rcvif(mreq); | | 732 | m_reset_rcvif(mreq); |
729 | *mbp = mb; | | 733 | *mbp = mb; |
730 | return (mreq); | | 734 | return (mreq); |
731 | } | | 735 | } |
732 | | | 736 | |
733 | /* | | 737 | /* |
734 | * copies mbuf chain to the uio scatter/gather list | | 738 | * copies mbuf chain to the uio scatter/gather list |
735 | */ | | 739 | */ |
736 | int | | 740 | int |
737 | nfsm_mbuftouio(struct mbuf **mrep, struct uio *uiop, int siz, char **dpos) | | 741 | nfsm_mbuftouio(struct mbuf **mrep, struct uio *uiop, int siz, char **dpos) |
738 | { | | 742 | { |
739 | char *mbufcp, *uiocp; | | 743 | char *mbufcp, *uiocp; |
740 | int xfer, left, len; | | 744 | int xfer, left, len; |
741 | struct mbuf *mp; | | 745 | struct mbuf *mp; |
742 | long uiosiz, rem; | | 746 | long uiosiz, rem; |
743 | int error = 0; | | 747 | int error = 0; |
744 | | | 748 | |
745 | mp = *mrep; | | 749 | mp = *mrep; |
746 | mbufcp = *dpos; | | 750 | mbufcp = *dpos; |
747 | len = mtod(mp, char *) + mp->m_len - mbufcp; | | 751 | len = mtod(mp, char *) + mp->m_len - mbufcp; |
748 | rem = nfsm_rndup(siz)-siz; | | 752 | rem = nfsm_rndup(siz)-siz; |
749 | while (siz > 0) { | | 753 | while (siz > 0) { |
750 | if (uiop->uio_iovcnt <= 0 || uiop->uio_iov == NULL) | | 754 | if (uiop->uio_iovcnt <= 0 || uiop->uio_iov == NULL) |
751 | return (EFBIG); | | 755 | return (EFBIG); |
752 | left = uiop->uio_iov->iov_len; | | 756 | left = uiop->uio_iov->iov_len; |
753 | uiocp = uiop->uio_iov->iov_base; | | 757 | uiocp = uiop->uio_iov->iov_base; |
754 | if (left > siz) | | 758 | if (left > siz) |
755 | left = siz; | | 759 | left = siz; |
756 | uiosiz = left; | | 760 | uiosiz = left; |
757 | while (left > 0) { | | 761 | while (left > 0) { |
758 | while (len == 0) { | | 762 | while (len == 0) { |
759 | mp = mp->m_next; | | 763 | mp = mp->m_next; |
760 | if (mp == NULL) | | 764 | if (mp == NULL) |
761 | return (EBADRPC); | | 765 | return (EBADRPC); |
762 | mbufcp = mtod(mp, void *); | | 766 | mbufcp = mtod(mp, void *); |
763 | len = mp->m_len; | | 767 | len = mp->m_len; |
764 | } | | 768 | } |
765 | xfer = (left > len) ? len : left; | | 769 | xfer = (left > len) ? len : left; |
766 | error = copyout_vmspace(uiop->uio_vmspace, mbufcp, | | 770 | error = copyout_vmspace(uiop->uio_vmspace, mbufcp, |
767 | uiocp, xfer); | | 771 | uiocp, xfer); |
768 | if (error) { | | 772 | if (error) { |
769 | return error; | | 773 | return error; |
770 | } | | 774 | } |
771 | left -= xfer; | | 775 | left -= xfer; |
772 | len -= xfer; | | 776 | len -= xfer; |
773 | mbufcp += xfer; | | 777 | mbufcp += xfer; |
774 | uiocp += xfer; | | 778 | uiocp += xfer; |
775 | uiop->uio_offset += xfer; | | 779 | uiop->uio_offset += xfer; |
776 | uiop->uio_resid -= xfer; | | 780 | uiop->uio_resid -= xfer; |
777 | } | | 781 | } |
778 | if (uiop->uio_iov->iov_len <= siz) { | | 782 | if (uiop->uio_iov->iov_len <= siz) { |
779 | uiop->uio_iovcnt--; | | 783 | uiop->uio_iovcnt--; |
780 | uiop->uio_iov++; | | 784 | uiop->uio_iov++; |
781 | } else { | | 785 | } else { |
782 | uiop->uio_iov->iov_base = | | 786 | uiop->uio_iov->iov_base = |
783 | (char *)uiop->uio_iov->iov_base + uiosiz; | | 787 | (char *)uiop->uio_iov->iov_base + uiosiz; |
784 | uiop->uio_iov->iov_len -= uiosiz; | | 788 | uiop->uio_iov->iov_len -= uiosiz; |
785 | } | | 789 | } |
786 | siz -= uiosiz; | | 790 | siz -= uiosiz; |
787 | } | | 791 | } |
788 | *dpos = mbufcp; | | 792 | *dpos = mbufcp; |
789 | *mrep = mp; | | 793 | *mrep = mp; |
790 | if (rem > 0) { | | 794 | if (rem > 0) { |
791 | if (len < rem) | | 795 | if (len < rem) |
792 | error = nfs_adv(mrep, dpos, rem, len); | | 796 | error = nfs_adv(mrep, dpos, rem, len); |
793 | else | | 797 | else |
794 | *dpos += rem; | | 798 | *dpos += rem; |
795 | } | | 799 | } |
796 | return (error); | | 800 | return (error); |
797 | } | | 801 | } |
798 | | | 802 | |
799 | /* | | 803 | /* |
800 | * copies a uio scatter/gather list to an mbuf chain. | | 804 | * copies a uio scatter/gather list to an mbuf chain. |
801 | * NOTE: can ony handle iovcnt == 1 | | 805 | * NOTE: can ony handle iovcnt == 1 |
802 | */ | | 806 | */ |
803 | int | | 807 | int |
804 | nfsm_uiotombuf(struct uio *uiop, struct mbuf **mq, int siz, char **bpos) | | 808 | nfsm_uiotombuf(struct uio *uiop, struct mbuf **mq, int siz, char **bpos) |
805 | { | | 809 | { |
806 | char *uiocp; | | 810 | char *uiocp; |
807 | struct mbuf *mp, *mp2; | | 811 | struct mbuf *mp, *mp2; |
808 | int xfer, left, mlen; | | 812 | int xfer, left, mlen; |
809 | int uiosiz, clflg, rem; | | 813 | int uiosiz, clflg, rem; |
810 | char *cp; | | 814 | char *cp; |
811 | int error; | | 815 | int error; |
812 | | | 816 | |
813 | #ifdef DIAGNOSTIC | | 817 | #ifdef DIAGNOSTIC |
814 | if (uiop->uio_iovcnt != 1) | | 818 | if (uiop->uio_iovcnt != 1) |
815 | panic("nfsm_uiotombuf: iovcnt != 1"); | | 819 | panic("nfsm_uiotombuf: iovcnt != 1"); |
816 | #endif | | 820 | #endif |
817 | | | 821 | |
818 | if (siz > MLEN) /* or should it >= MCLBYTES ?? */ | | 822 | if (siz > MLEN) /* or should it >= MCLBYTES ?? */ |
819 | clflg = 1; | | 823 | clflg = 1; |
820 | else | | 824 | else |
821 | clflg = 0; | | 825 | clflg = 0; |
822 | rem = nfsm_rndup(siz)-siz; | | 826 | rem = nfsm_rndup(siz)-siz; |
823 | mp = mp2 = *mq; | | 827 | mp = mp2 = *mq; |
824 | while (siz > 0) { | | 828 | while (siz > 0) { |
825 | left = uiop->uio_iov->iov_len; | | 829 | left = uiop->uio_iov->iov_len; |
826 | uiocp = uiop->uio_iov->iov_base; | | 830 | uiocp = uiop->uio_iov->iov_base; |
827 | if (left > siz) | | 831 | if (left > siz) |
828 | left = siz; | | 832 | left = siz; |
829 | uiosiz = left; | | 833 | uiosiz = left; |
830 | while (left > 0) { | | 834 | while (left > 0) { |
831 | mlen = M_TRAILINGSPACE(mp); | | 835 | mlen = M_TRAILINGSPACE(mp); |
832 | if (mlen == 0) { | | 836 | if (mlen == 0) { |
833 | mp = m_get(M_WAIT, MT_DATA); | | 837 | mp = m_get(M_WAIT, MT_DATA); |
834 | MCLAIM(mp, &nfs_mowner); | | 838 | MCLAIM(mp, &nfs_mowner); |
835 | if (clflg) | | 839 | if (clflg) |
836 | m_clget(mp, M_WAIT); | | 840 | m_clget(mp, M_WAIT); |
837 | mp->m_len = 0; | | 841 | mp->m_len = 0; |
838 | mp2->m_next = mp; | | 842 | mp2->m_next = mp; |
839 | mp2 = mp; | | 843 | mp2 = mp; |
840 | mlen = M_TRAILINGSPACE(mp); | | 844 | mlen = M_TRAILINGSPACE(mp); |
841 | } | | 845 | } |
842 | xfer = (left > mlen) ? mlen : left; | | 846 | xfer = (left > mlen) ? mlen : left; |
843 | cp = mtod(mp, char *) + mp->m_len; | | 847 | cp = mtod(mp, char *) + mp->m_len; |
844 | error = copyin_vmspace(uiop->uio_vmspace, uiocp, cp, | | 848 | error = copyin_vmspace(uiop->uio_vmspace, uiocp, cp, |
845 | xfer); | | 849 | xfer); |
846 | if (error) { | | 850 | if (error) { |
847 | /* XXX */ | | 851 | /* XXX */ |
848 | } | | 852 | } |
849 | mp->m_len += xfer; | | 853 | mp->m_len += xfer; |
850 | left -= xfer; | | 854 | left -= xfer; |
851 | uiocp += xfer; | | 855 | uiocp += xfer; |
852 | uiop->uio_offset += xfer; | | 856 | uiop->uio_offset += xfer; |
853 | uiop->uio_resid -= xfer; | | 857 | uiop->uio_resid -= xfer; |
854 | } | | 858 | } |
855 | uiop->uio_iov->iov_base = (char *)uiop->uio_iov->iov_base + | | 859 | uiop->uio_iov->iov_base = (char *)uiop->uio_iov->iov_base + |
856 | uiosiz; | | 860 | uiosiz; |
857 | uiop->uio_iov->iov_len -= uiosiz; | | 861 | uiop->uio_iov->iov_len -= uiosiz; |
858 | siz -= uiosiz; | | 862 | siz -= uiosiz; |
859 | } | | 863 | } |
860 | if (rem > 0) { | | 864 | if (rem > 0) { |
861 | if (rem > M_TRAILINGSPACE(mp)) { | | 865 | if (rem > M_TRAILINGSPACE(mp)) { |
862 | mp = m_get(M_WAIT, MT_DATA); | | 866 | mp = m_get(M_WAIT, MT_DATA); |
863 | MCLAIM(mp, &nfs_mowner); | | 867 | MCLAIM(mp, &nfs_mowner); |
864 | mp->m_len = 0; | | 868 | mp->m_len = 0; |
865 | mp2->m_next = mp; | | 869 | mp2->m_next = mp; |
866 | } | | 870 | } |
867 | cp = mtod(mp, char *) + mp->m_len; | | 871 | cp = mtod(mp, char *) + mp->m_len; |
868 | for (left = 0; left < rem; left++) | | 872 | for (left = 0; left < rem; left++) |
869 | *cp++ = '\0'; | | 873 | *cp++ = '\0'; |
870 | mp->m_len += rem; | | 874 | mp->m_len += rem; |
871 | *bpos = cp; | | 875 | *bpos = cp; |
872 | } else | | 876 | } else |
873 | *bpos = mtod(mp, char *) + mp->m_len; | | 877 | *bpos = mtod(mp, char *) + mp->m_len; |
874 | *mq = mp; | | 878 | *mq = mp; |
875 | return (0); | | 879 | return (0); |
876 | } | | 880 | } |
877 | | | 881 | |
878 | /* | | 882 | /* |
879 | * Get at least "siz" bytes of correctly aligned data. | | 883 | * Get at least "siz" bytes of correctly aligned data. |
880 | * When called the mbuf pointers are not necessarily correct, | | 884 | * When called the mbuf pointers are not necessarily correct, |
881 | * dsosp points to what ought to be in m_data and left contains | | 885 | * dsosp points to what ought to be in m_data and left contains |
882 | * what ought to be in m_len. | | 886 | * what ought to be in m_len. |
883 | * This is used by the macros nfsm_dissect and nfsm_dissecton for tough | | 887 | * This is used by the macros nfsm_dissect and nfsm_dissecton for tough |
884 | * cases. (The macros use the vars. dpos and dpos2) | | 888 | * cases. (The macros use the vars. dpos and dpos2) |
885 | */ | | 889 | */ |
886 | int | | 890 | int |
887 | nfsm_disct(struct mbuf **mdp, char **dposp, int siz, int left, char **cp2) | | 891 | nfsm_disct(struct mbuf **mdp, char **dposp, int siz, int left, char **cp2) |
888 | { | | 892 | { |
889 | struct mbuf *m1, *m2; | | 893 | struct mbuf *m1, *m2; |
890 | struct mbuf *havebuf = NULL; | | 894 | struct mbuf *havebuf = NULL; |
891 | char *src = *dposp; | | 895 | char *src = *dposp; |
892 | char *dst; | | 896 | char *dst; |
893 | int len; | | 897 | int len; |
894 | | | 898 | |
895 | #ifdef DEBUG | | 899 | #ifdef DEBUG |
896 | if (left < 0) | | 900 | if (left < 0) |
897 | panic("nfsm_disct: left < 0"); | | 901 | panic("nfsm_disct: left < 0"); |
898 | #endif | | 902 | #endif |
899 | m1 = *mdp; | | 903 | m1 = *mdp; |
900 | /* | | 904 | /* |
901 | * Skip through the mbuf chain looking for an mbuf with | | 905 | * Skip through the mbuf chain looking for an mbuf with |
902 | * some data. If the first mbuf found has enough data | | 906 | * some data. If the first mbuf found has enough data |
903 | * and it is correctly aligned return it. | | 907 | * and it is correctly aligned return it. |
904 | */ | | 908 | */ |
905 | while (left == 0) { | | 909 | while (left == 0) { |
906 | havebuf = m1; | | 910 | havebuf = m1; |
907 | *mdp = m1 = m1->m_next; | | 911 | *mdp = m1 = m1->m_next; |
908 | if (m1 == NULL) | | 912 | if (m1 == NULL) |
909 | return (EBADRPC); | | 913 | return (EBADRPC); |
910 | src = mtod(m1, void *); | | 914 | src = mtod(m1, void *); |
911 | left = m1->m_len; | | 915 | left = m1->m_len; |
912 | /* | | 916 | /* |
913 | * If we start a new mbuf and it is big enough | | 917 | * If we start a new mbuf and it is big enough |
914 | * and correctly aligned just return it, don't | | 918 | * and correctly aligned just return it, don't |
915 | * do any pull up. | | 919 | * do any pull up. |
916 | */ | | 920 | */ |
917 | if (left >= siz && nfsm_aligned(src)) { | | 921 | if (left >= siz && nfsm_aligned(src)) { |
918 | *cp2 = src; | | 922 | *cp2 = src; |
919 | *dposp = src + siz; | | 923 | *dposp = src + siz; |
920 | return (0); | | 924 | return (0); |
921 | } | | 925 | } |
922 | } | | 926 | } |
923 | if ((m1->m_flags & M_EXT) != 0) { | | 927 | if ((m1->m_flags & M_EXT) != 0) { |
924 | if (havebuf && M_TRAILINGSPACE(havebuf) >= siz && | | 928 | if (havebuf && M_TRAILINGSPACE(havebuf) >= siz && |
925 | nfsm_aligned(mtod(havebuf, char *) + havebuf->m_len)) { | | 929 | nfsm_aligned(mtod(havebuf, char *) + havebuf->m_len)) { |
926 | /* | | 930 | /* |
927 | * If the first mbuf with data has external data | | 931 | * If the first mbuf with data has external data |
928 | * and there is a previous mbuf with some trailing | | 932 | * and there is a previous mbuf with some trailing |
929 | * space, use it to move the data into. | | 933 | * space, use it to move the data into. |
930 | */ | | 934 | */ |
931 | m2 = m1; | | 935 | m2 = m1; |
932 | *mdp = m1 = havebuf; | | 936 | *mdp = m1 = havebuf; |
933 | *cp2 = mtod(m1, char *) + m1->m_len; | | 937 | *cp2 = mtod(m1, char *) + m1->m_len; |
934 | } else if (havebuf) { | | 938 | } else if (havebuf) { |
935 | /* | | 939 | /* |
936 | * If the first mbuf has a external data | | 940 | * If the first mbuf has a external data |
937 | * and there is no previous empty mbuf | | 941 | * and there is no previous empty mbuf |
938 | * allocate a new mbuf and move the external | | 942 | * allocate a new mbuf and move the external |
939 | * data to the new mbuf. Also make the first | | 943 | * data to the new mbuf. Also make the first |
940 | * mbuf look empty. | | 944 | * mbuf look empty. |
941 | */ | | 945 | */ |
942 | m2 = m1; | | 946 | m2 = m1; |
943 | *mdp = m1 = m_get(M_WAIT, MT_DATA); | | 947 | *mdp = m1 = m_get(M_WAIT, MT_DATA); |
944 | MCLAIM(m1, m2->m_owner); | | 948 | MCLAIM(m1, m2->m_owner); |
945 | if ((m2->m_flags & M_PKTHDR) != 0) { | | 949 | if ((m2->m_flags & M_PKTHDR) != 0) { |
946 | m_move_pkthdr(m1, m2); | | 950 | m_move_pkthdr(m1, m2); |
947 | } | | 951 | } |
948 | if (havebuf) { | | 952 | if (havebuf) { |
949 | havebuf->m_next = m1; | | 953 | havebuf->m_next = m1; |
950 | } | | 954 | } |
951 | m1->m_next = m2; | | 955 | m1->m_next = m2; |
952 | MRESETDATA(m1); | | 956 | MRESETDATA(m1); |
953 | m1->m_len = 0; | | 957 | m1->m_len = 0; |
954 | m2->m_data = src; | | 958 | m2->m_data = src; |
955 | m2->m_len = left; | | 959 | m2->m_len = left; |
956 | *cp2 = mtod(m1, char *); | | 960 | *cp2 = mtod(m1, char *); |
957 | } else { | | 961 | } else { |
958 | struct mbuf **nextp = &m1->m_next; | | 962 | struct mbuf **nextp = &m1->m_next; |
959 | | | 963 | |
960 | m1->m_len -= left; | | 964 | m1->m_len -= left; |
961 | do { | | 965 | do { |
962 | m2 = m_get(M_WAIT, MT_DATA); | | 966 | m2 = m_get(M_WAIT, MT_DATA); |
963 | MCLAIM(m2, m1->m_owner); | | 967 | MCLAIM(m2, m1->m_owner); |
964 | if (left >= MINCLSIZE) { | | 968 | if (left >= MINCLSIZE) { |
965 | MCLGET(m2, M_WAIT); | | 969 | MCLGET(m2, M_WAIT); |
966 | } | | 970 | } |
967 | m2->m_next = *nextp; | | 971 | m2->m_next = *nextp; |
968 | *nextp = m2; | | 972 | *nextp = m2; |
969 | nextp = &m2->m_next; | | 973 | nextp = &m2->m_next; |
970 | len = (m2->m_flags & M_EXT) != 0 ? | | 974 | len = (m2->m_flags & M_EXT) != 0 ? |
971 | MCLBYTES : MLEN; | | 975 | MCLBYTES : MLEN; |
972 | if (len > left) { | | 976 | if (len > left) { |
973 | len = left; | | 977 | len = left; |
974 | } | | 978 | } |
975 | memcpy(mtod(m2, char *), src, len); | | 979 | memcpy(mtod(m2, char *), src, len); |
976 | m2->m_len = len; | | 980 | m2->m_len = len; |
977 | src += len; | | 981 | src += len; |
978 | left -= len; | | 982 | left -= len; |
979 | } while (left > 0); | | 983 | } while (left > 0); |
980 | *mdp = m1 = m1->m_next; | | 984 | *mdp = m1 = m1->m_next; |
981 | m2 = m1->m_next; | | 985 | m2 = m1->m_next; |
982 | *cp2 = mtod(m1, char *); | | 986 | *cp2 = mtod(m1, char *); |
983 | } | | 987 | } |
984 | } else { | | 988 | } else { |
985 | /* | | 989 | /* |
986 | * If the first mbuf has no external data | | 990 | * If the first mbuf has no external data |
987 | * move the data to the front of the mbuf. | | 991 | * move the data to the front of the mbuf. |
988 | */ | | 992 | */ |
989 | MRESETDATA(m1); | | 993 | MRESETDATA(m1); |
990 | dst = mtod(m1, char *); | | 994 | dst = mtod(m1, char *); |
991 | if (dst != src) { | | 995 | if (dst != src) { |
992 | memmove(dst, src, left); | | 996 | memmove(dst, src, left); |
993 | } | | 997 | } |
994 | m1->m_len = left; | | 998 | m1->m_len = left; |
995 | m2 = m1->m_next; | | 999 | m2 = m1->m_next; |
996 | *cp2 = m1->m_data; | | 1000 | *cp2 = m1->m_data; |
997 | } | | 1001 | } |
998 | *dposp = *cp2 + siz; | | 1002 | *dposp = *cp2 + siz; |
999 | /* | | 1003 | /* |
1000 | * Loop through mbufs pulling data up into first mbuf until | | 1004 | * Loop through mbufs pulling data up into first mbuf until |
1001 | * the first mbuf is full or there is no more data to | | 1005 | * the first mbuf is full or there is no more data to |
1002 | * pullup. | | 1006 | * pullup. |
1003 | */ | | 1007 | */ |
1004 | dst = mtod(m1, char *) + m1->m_len; | | 1008 | dst = mtod(m1, char *) + m1->m_len; |
1005 | while ((len = M_TRAILINGSPACE(m1)) != 0 && m2) { | | 1009 | while ((len = M_TRAILINGSPACE(m1)) != 0 && m2) { |
1006 | if ((len = uimin(len, m2->m_len)) != 0) { | | 1010 | if ((len = uimin(len, m2->m_len)) != 0) { |
1007 | memcpy(dst, mtod(m2, char *), len); | | 1011 | memcpy(dst, mtod(m2, char *), len); |
1008 | } | | 1012 | } |
1009 | m1->m_len += len; | | 1013 | m1->m_len += len; |
1010 | dst += len; | | 1014 | dst += len; |
1011 | m2->m_data += len; | | 1015 | m2->m_data += len; |
1012 | m2->m_len -= len; | | 1016 | m2->m_len -= len; |
1013 | m2 = m2->m_next; | | 1017 | m2 = m2->m_next; |
1014 | } | | 1018 | } |
1015 | if (m1->m_len < siz) | | 1019 | if (m1->m_len < siz) |
1016 | return (EBADRPC); | | 1020 | return (EBADRPC); |
1017 | return (0); | | 1021 | return (0); |
1018 | } | | 1022 | } |
1019 | | | 1023 | |
1020 | /* | | 1024 | /* |
1021 | * Advance the position in the mbuf chain. | | 1025 | * Advance the position in the mbuf chain. |
1022 | */ | | 1026 | */ |
1023 | int | | 1027 | int |
1024 | nfs_adv(struct mbuf **mdp, char **dposp, int offs, int left) | | 1028 | nfs_adv(struct mbuf **mdp, char **dposp, int offs, int left) |
1025 | { | | 1029 | { |
1026 | struct mbuf *m; | | 1030 | struct mbuf *m; |
1027 | int s; | | 1031 | int s; |
1028 | | | 1032 | |
1029 | m = *mdp; | | 1033 | m = *mdp; |
1030 | s = left; | | 1034 | s = left; |
1031 | while (s < offs) { | | 1035 | while (s < offs) { |
1032 | offs -= s; | | 1036 | offs -= s; |
1033 | m = m->m_next; | | 1037 | m = m->m_next; |
1034 | if (m == NULL) | | 1038 | if (m == NULL) |
1035 | return (EBADRPC); | | 1039 | return (EBADRPC); |
1036 | s = m->m_len; | | 1040 | s = m->m_len; |
1037 | } | | 1041 | } |
1038 | *mdp = m; | | 1042 | *mdp = m; |
1039 | *dposp = mtod(m, char *) + offs; | | 1043 | *dposp = mtod(m, char *) + offs; |
1040 | return (0); | | 1044 | return (0); |
1041 | } | | 1045 | } |
1042 | | | 1046 | |
1043 | /* | | 1047 | /* |
1044 | * Copy a string into mbufs for the hard cases... | | 1048 | * Copy a string into mbufs for the hard cases... |
1045 | */ | | 1049 | */ |
1046 | int | | 1050 | int |
1047 | nfsm_strtmbuf(struct mbuf **mb, char **bpos, const char *cp, long siz) | | 1051 | nfsm_strtmbuf(struct mbuf **mb, char **bpos, const char *cp, long siz) |
1048 | { | | 1052 | { |
1049 | struct mbuf *m1 = NULL, *m2; | | 1053 | struct mbuf *m1 = NULL, *m2; |
1050 | long left, xfer, len, tlen; | | 1054 | long left, xfer, len, tlen; |
1051 | u_int32_t *tl; | | 1055 | u_int32_t *tl; |
1052 | int putsize; | | 1056 | int putsize; |
1053 | | | 1057 | |
1054 | putsize = 1; | | 1058 | putsize = 1; |
1055 | m2 = *mb; | | 1059 | m2 = *mb; |
1056 | left = M_TRAILINGSPACE(m2); | | 1060 | left = M_TRAILINGSPACE(m2); |
1057 | if (left > 0) { | | 1061 | if (left > 0) { |
1058 | tl = ((u_int32_t *)(*bpos)); | | 1062 | tl = ((u_int32_t *)(*bpos)); |
1059 | *tl++ = txdr_unsigned(siz); | | 1063 | *tl++ = txdr_unsigned(siz); |
1060 | putsize = 0; | | 1064 | putsize = 0; |
1061 | left -= NFSX_UNSIGNED; | | 1065 | left -= NFSX_UNSIGNED; |
1062 | m2->m_len += NFSX_UNSIGNED; | | 1066 | m2->m_len += NFSX_UNSIGNED; |
1063 | if (left > 0) { | | 1067 | if (left > 0) { |
1064 | memcpy((void *) tl, cp, left); | | 1068 | memcpy((void *) tl, cp, left); |
1065 | siz -= left; | | 1069 | siz -= left; |
1066 | cp += left; | | 1070 | cp += left; |
1067 | m2->m_len += left; | | 1071 | m2->m_len += left; |
1068 | left = 0; | | 1072 | left = 0; |
1069 | } | | 1073 | } |
1070 | } | | 1074 | } |
1071 | /* Loop around adding mbufs */ | | 1075 | /* Loop around adding mbufs */ |
1072 | while (siz > 0) { | | 1076 | while (siz > 0) { |
1073 | m1 = m_get(M_WAIT, MT_DATA); | | 1077 | m1 = m_get(M_WAIT, MT_DATA); |
1074 | MCLAIM(m1, &nfs_mowner); | | 1078 | MCLAIM(m1, &nfs_mowner); |
1075 | if (siz > MLEN) | | 1079 | if (siz > MLEN) |
1076 | m_clget(m1, M_WAIT); | | 1080 | m_clget(m1, M_WAIT); |
1077 | m1->m_len = NFSMSIZ(m1); | | 1081 | m1->m_len = NFSMSIZ(m1); |
1078 | m2->m_next = m1; | | 1082 | m2->m_next = m1; |
1079 | m2 = m1; | | 1083 | m2 = m1; |
1080 | tl = mtod(m1, u_int32_t *); | | 1084 | tl = mtod(m1, u_int32_t *); |
1081 | tlen = 0; | | 1085 | tlen = 0; |
1082 | if (putsize) { | | 1086 | if (putsize) { |
1083 | *tl++ = txdr_unsigned(siz); | | 1087 | *tl++ = txdr_unsigned(siz); |
1084 | m1->m_len -= NFSX_UNSIGNED; | | 1088 | m1->m_len -= NFSX_UNSIGNED; |
1085 | tlen = NFSX_UNSIGNED; | | 1089 | tlen = NFSX_UNSIGNED; |
1086 | putsize = 0; | | 1090 | putsize = 0; |
1087 | } | | 1091 | } |
1088 | if (siz < m1->m_len) { | | 1092 | if (siz < m1->m_len) { |
1089 | len = nfsm_rndup(siz); | | 1093 | len = nfsm_rndup(siz); |
1090 | xfer = siz; | | 1094 | xfer = siz; |
1091 | if (xfer < len) | | 1095 | if (xfer < len) |
1092 | *(tl+(xfer>>2)) = 0; | | 1096 | *(tl+(xfer>>2)) = 0; |
1093 | } else { | | 1097 | } else { |
1094 | xfer = len = m1->m_len; | | 1098 | xfer = len = m1->m_len; |
1095 | } | | 1099 | } |
1096 | memcpy((void *) tl, cp, xfer); | | 1100 | memcpy((void *) tl, cp, xfer); |
1097 | m1->m_len = len+tlen; | | 1101 | m1->m_len = len+tlen; |
1098 | siz -= xfer; | | 1102 | siz -= xfer; |
1099 | cp += xfer; | | 1103 | cp += xfer; |
1100 | } | | 1104 | } |
1101 | *mb = m1; | | 1105 | *mb = m1; |
1102 | *bpos = mtod(m1, char *) + m1->m_len; | | 1106 | *bpos = mtod(m1, char *) + m1->m_len; |
1103 | return (0); | | 1107 | return (0); |
1104 | } | | 1108 | } |
1105 | | | 1109 | |
1106 | /* | | 1110 | /* |
1107 | * Directory caching routines. They work as follows: | | 1111 | * Directory caching routines. They work as follows: |
1108 | * - a cache is maintained per VDIR nfsnode. | | 1112 | * - a cache is maintained per VDIR nfsnode. |
1109 | * - for each offset cookie that is exported to userspace, and can | | 1113 | * - for each offset cookie that is exported to userspace, and can |
1110 | * thus be thrown back at us as an offset to VOP_READDIR, store | | 1114 | * thus be thrown back at us as an offset to VOP_READDIR, store |
1111 | * information in the cache. | | 1115 | * information in the cache. |
1112 | * - cached are: | | 1116 | * - cached are: |
1113 | * - cookie itself | | 1117 | * - cookie itself |
1114 | * - blocknumber (essentially just a search key in the buffer cache) | | 1118 | * - blocknumber (essentially just a search key in the buffer cache) |
1115 | * - entry number in block. | | 1119 | * - entry number in block. |
1116 | * - offset cookie of block in which this entry is stored | | 1120 | * - offset cookie of block in which this entry is stored |
1117 | * - 32 bit cookie if NFSMNT_XLATECOOKIE is used. | | 1121 | * - 32 bit cookie if NFSMNT_XLATECOOKIE is used. |
1118 | * - entries are looked up in a hash table | | 1122 | * - entries are looked up in a hash table |
1119 | * - also maintained is an LRU list of entries, used to determine | | 1123 | * - also maintained is an LRU list of entries, used to determine |
1120 | * which ones to delete if the cache grows too large. | | 1124 | * which ones to delete if the cache grows too large. |
1121 | * - if 32 <-> 64 translation mode is requested for a filesystem, | | 1125 | * - if 32 <-> 64 translation mode is requested for a filesystem, |
1122 | * the cache also functions as a translation table | | 1126 | * the cache also functions as a translation table |
1123 | * - in the translation case, invalidating the cache does not mean | | 1127 | * - in the translation case, invalidating the cache does not mean |
1124 | * flushing it, but just marking entries as invalid, except for | | 1128 | * flushing it, but just marking entries as invalid, except for |
1125 | * the <64bit cookie, 32bitcookie> pair which is still valid, to | | 1129 | * the <64bit cookie, 32bitcookie> pair which is still valid, to |
1126 | * still be able to use the cache as a translation table. | | 1130 | * still be able to use the cache as a translation table. |
1127 | * - 32 bit cookies are uniquely created by combining the hash table | | 1131 | * - 32 bit cookies are uniquely created by combining the hash table |
1128 | * entry value, and one generation count per hash table entry, | | 1132 | * entry value, and one generation count per hash table entry, |
1129 | * incremented each time an entry is appended to the chain. | | 1133 | * incremented each time an entry is appended to the chain. |
1130 | * - the cache is invalidated each time a direcory is modified | | 1134 | * - the cache is invalidated each time a direcory is modified |
1131 | * - sanity checks are also done; if an entry in a block turns | | 1135 | * - sanity checks are also done; if an entry in a block turns |
1132 | * out not to have a matching cookie, the cache is invalidated | | 1136 | * out not to have a matching cookie, the cache is invalidated |
1133 | * and a new block starting from the wanted offset is fetched from | | 1137 | * and a new block starting from the wanted offset is fetched from |
1134 | * the server. | | 1138 | * the server. |
1135 | * - directory entries as read from the server are extended to contain | | 1139 | * - directory entries as read from the server are extended to contain |
1136 | * the 64bit and, optionally, the 32bit cookies, for sanity checking | | 1140 | * the 64bit and, optionally, the 32bit cookies, for sanity checking |
1137 | * the cache and exporting them to userspace through the cookie | | 1141 | * the cache and exporting them to userspace through the cookie |
1138 | * argument to VOP_READDIR. | | 1142 | * argument to VOP_READDIR. |
1139 | */ | | 1143 | */ |
1140 | | | 1144 | |
1141 | u_long | | 1145 | u_long |
1142 | nfs_dirhash(off_t off) | | 1146 | nfs_dirhash(off_t off) |
1143 | { | | 1147 | { |
1144 | int i; | | 1148 | int i; |
1145 | char *cp = (char *)&off; | | 1149 | char *cp = (char *)&off; |
1146 | u_long sum = 0L; | | 1150 | u_long sum = 0L; |
1147 | | | 1151 | |
1148 | for (i = 0 ; i < sizeof (off); i++) | | 1152 | for (i = 0 ; i < sizeof (off); i++) |
1149 | sum += *cp++; | | 1153 | sum += *cp++; |
1150 | | | 1154 | |
1151 | return sum; | | 1155 | return sum; |
1152 | } | | 1156 | } |
1153 | | | 1157 | |
1154 | #define _NFSDC_MTX(np) (NFSTOV(np)->v_interlock) | | 1158 | #define _NFSDC_MTX(np) (NFSTOV(np)->v_interlock) |
1155 | #define NFSDC_LOCK(np) mutex_enter(_NFSDC_MTX(np)) | | 1159 | #define NFSDC_LOCK(np) mutex_enter(_NFSDC_MTX(np)) |
1156 | #define NFSDC_UNLOCK(np) mutex_exit(_NFSDC_MTX(np)) | | 1160 | #define NFSDC_UNLOCK(np) mutex_exit(_NFSDC_MTX(np)) |
1157 | #define NFSDC_ASSERT_LOCKED(np) KASSERT(mutex_owned(_NFSDC_MTX(np))) | | 1161 | #define NFSDC_ASSERT_LOCKED(np) KASSERT(mutex_owned(_NFSDC_MTX(np))) |
1158 | | | 1162 | |
1159 | void | | 1163 | void |
1160 | nfs_initdircache(struct vnode *vp) | | 1164 | nfs_initdircache(struct vnode *vp) |
1161 | { | | 1165 | { |
1162 | struct nfsnode *np = VTONFS(vp); | | 1166 | struct nfsnode *np = VTONFS(vp); |
1163 | struct nfsdirhashhead *dircache; | | 1167 | struct nfsdirhashhead *dircache; |
1164 | | | 1168 | |
1165 | dircache = hashinit(NFS_DIRHASHSIZ, HASH_LIST, true, | | 1169 | dircache = hashinit(NFS_DIRHASHSIZ, HASH_LIST, true, |
1166 | &nfsdirhashmask); | | 1170 | &nfsdirhashmask); |
1167 | | | 1171 | |
1168 | NFSDC_LOCK(np); | | 1172 | NFSDC_LOCK(np); |
1169 | if (np->n_dircache == NULL) { | | 1173 | if (np->n_dircache == NULL) { |
1170 | np->n_dircachesize = 0; | | 1174 | np->n_dircachesize = 0; |
1171 | np->n_dircache = dircache; | | 1175 | np->n_dircache = dircache; |
1172 | dircache = NULL; | | 1176 | dircache = NULL; |
1173 | TAILQ_INIT(&np->n_dirchain); | | 1177 | TAILQ_INIT(&np->n_dirchain); |
1174 | } | | 1178 | } |
1175 | NFSDC_UNLOCK(np); | | 1179 | NFSDC_UNLOCK(np); |
1176 | if (dircache) | | 1180 | if (dircache) |
1177 | hashdone(dircache, HASH_LIST, nfsdirhashmask); | | 1181 | hashdone(dircache, HASH_LIST, nfsdirhashmask); |
1178 | } | | 1182 | } |
1179 | | | 1183 | |
1180 | void | | 1184 | void |
1181 | nfs_initdirxlatecookie(struct vnode *vp) | | 1185 | nfs_initdirxlatecookie(struct vnode *vp) |
1182 | { | | 1186 | { |
1183 | struct nfsnode *np = VTONFS(vp); | | 1187 | struct nfsnode *np = VTONFS(vp); |
1184 | unsigned *dirgens; | | 1188 | unsigned *dirgens; |
1185 | | | 1189 | |
1186 | KASSERT(VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_XLATECOOKIE); | | 1190 | KASSERT(VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_XLATECOOKIE); |
1187 | | | 1191 | |
1188 | dirgens = kmem_zalloc(NFS_DIRHASHSIZ * sizeof(unsigned), KM_SLEEP); | | 1192 | dirgens = kmem_zalloc(NFS_DIRHASHSIZ * sizeof(unsigned), KM_SLEEP); |
1189 | NFSDC_LOCK(np); | | 1193 | NFSDC_LOCK(np); |
1190 | if (np->n_dirgens == NULL) { | | 1194 | if (np->n_dirgens == NULL) { |
1191 | np->n_dirgens = dirgens; | | 1195 | np->n_dirgens = dirgens; |
1192 | dirgens = NULL; | | 1196 | dirgens = NULL; |
1193 | } | | 1197 | } |
1194 | NFSDC_UNLOCK(np); | | 1198 | NFSDC_UNLOCK(np); |
1195 | if (dirgens) | | 1199 | if (dirgens) |
1196 | kmem_free(dirgens, NFS_DIRHASHSIZ * sizeof(unsigned)); | | 1200 | kmem_free(dirgens, NFS_DIRHASHSIZ * sizeof(unsigned)); |
1197 | } | | 1201 | } |
1198 | | | 1202 | |
1199 | static const struct nfsdircache dzero; | | 1203 | static const struct nfsdircache dzero; |
1200 | | | 1204 | |
1201 | static void nfs_unlinkdircache(struct nfsnode *np, struct nfsdircache *); | | 1205 | static void nfs_unlinkdircache(struct nfsnode *np, struct nfsdircache *); |
1202 | static void nfs_putdircache_unlocked(struct nfsnode *, | | 1206 | static void nfs_putdircache_unlocked(struct nfsnode *, |
1203 | struct nfsdircache *); | | 1207 | struct nfsdircache *); |
1204 | | | 1208 | |
1205 | static void | | 1209 | static void |
1206 | nfs_unlinkdircache(struct nfsnode *np, struct nfsdircache *ndp) | | 1210 | nfs_unlinkdircache(struct nfsnode *np, struct nfsdircache *ndp) |
1207 | { | | 1211 | { |
1208 | | | 1212 | |
1209 | NFSDC_ASSERT_LOCKED(np); | | 1213 | NFSDC_ASSERT_LOCKED(np); |
1210 | KASSERT(ndp != &dzero); | | 1214 | KASSERT(ndp != &dzero); |
1211 | | | 1215 | |
1212 | if (LIST_NEXT(ndp, dc_hash) == (void *)-1) | | 1216 | if (LIST_NEXT(ndp, dc_hash) == (void *)-1) |
1213 | return; | | 1217 | return; |
1214 | | | 1218 | |
1215 | TAILQ_REMOVE(&np->n_dirchain, ndp, dc_chain); | | 1219 | TAILQ_REMOVE(&np->n_dirchain, ndp, dc_chain); |
1216 | LIST_REMOVE(ndp, dc_hash); | | 1220 | LIST_REMOVE(ndp, dc_hash); |
1217 | LIST_NEXT(ndp, dc_hash) = (void *)-1; /* mark as unlinked */ | | 1221 | LIST_NEXT(ndp, dc_hash) = (void *)-1; /* mark as unlinked */ |
1218 | | | 1222 | |
1219 | nfs_putdircache_unlocked(np, ndp); | | 1223 | nfs_putdircache_unlocked(np, ndp); |
1220 | } | | 1224 | } |
1221 | | | 1225 | |
1222 | void | | 1226 | void |
1223 | nfs_putdircache(struct nfsnode *np, struct nfsdircache *ndp) | | 1227 | nfs_putdircache(struct nfsnode *np, struct nfsdircache *ndp) |
1224 | { | | 1228 | { |
1225 | int ref; | | 1229 | int ref; |
1226 | | | 1230 | |
1227 | if (ndp == &dzero) | | 1231 | if (ndp == &dzero) |