Print this page
NEX-16818 Add fksmbcl development tool
NEX-17264 SMB client test tp_smbutil_013 fails after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (fix ref leaks)
5404 smbfs needs mmap support
Portions contributed by: Gordon Ross <gordon.w.ross@gmail.com>
Reviewed by: C Fraire <cfraire@me.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c
+++ new/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c
1 1 /*
2 2 * Copyright (c) 2000-2001 Boris Popov
3 3 * All rights reserved.
4 4 *
5 5 * Redistribution and use in source and binary forms, with or without
6 6 * modification, are permitted provided that the following conditions
7 7 * are met:
8 8 * 1. Redistributions of source code must retain the above copyright
9 9 * notice, this list of conditions and the following disclaimer.
10 10 * 2. Redistributions in binary form must reproduce the above copyright
11 11 * notice, this list of conditions and the following disclaimer in the
12 12 * documentation and/or other materials provided with the distribution.
13 13 * 3. All advertising materials mentioning features or use of this software
14 14 * must display the following acknowledgement:
15 15 * This product includes software developed by Boris Popov.
16 16 * 4. Neither the name of the author nor the names of any co-contributors
17 17 * may be used to endorse or promote products derived from this software
18 18 * without specific prior written permission.
19 19 *
20 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
28 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 30 * SUCH DAMAGE.
31 31 *
32 32 * $Id: smbfs_node.c,v 1.54.52.1 2005/05/27 02:35:28 lindak Exp $
33 33 */
34 34
35 35 /*
36 36 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
37 37 * Use is subject to license terms.
38 + *
39 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
38 40 */
39 41
40 42 #include <sys/param.h>
41 43 #include <sys/systm.h>
42 44 #include <sys/cred.h>
45 +#include <sys/errno.h>
43 46 #include <sys/time.h>
44 47 #include <sys/vfs.h>
45 48 #include <sys/vnode.h>
46 49 #include <sys/kmem.h>
47 50 #include <sys/stat.h>
48 51 #include <sys/atomic.h>
49 52 #include <sys/cmn_err.h>
50 53 #include <sys/sysmacros.h>
51 54 #include <sys/bitmap.h>
52 55
53 56 #include <netsmb/smb_osdep.h>
54 57
55 58 #include <netsmb/smb.h>
56 59 #include <netsmb/smb_conn.h>
57 60 #include <netsmb/smb_subr.h>
58 61
59 62 #include <smbfs/smbfs.h>
60 63 #include <smbfs/smbfs_node.h>
61 64 #include <smbfs/smbfs_subr.h>
62 65
63 66 /*
64 67 * Lack of inode numbers leads us to the problem of generating them.
65 68 * Partially this problem can be solved by having a dir/file cache
66 69 * with inode numbers generated from the incremented by one counter.
67 70 * However this way will require too much kernel memory, gives all
68 71 * sorts of locking and consistency problems, not to mentinon counter
69 72 * overflows. So, I'm decided to use a hash function to generate
70 73 * pseudo random (and [often?] unique) inode numbers.
71 74 */
72 75
73 76 /* Magic constants for name hashing. */
74 77 #define FNV_32_PRIME ((uint32_t)0x01000193UL)
75 78 #define FNV1_32_INIT ((uint32_t)33554467UL)
76 79
77 80 static inline uint32_t
78 81 smbfs_hash(uint32_t ival, const char *name, int nmlen)
79 82 {
80 83 uint32_t v;
81 84
82 85 for (v = ival; nmlen; name++, nmlen--) {
83 86 v *= FNV_32_PRIME;
84 87 v ^= (uint32_t)*name;
85 88 }
86 89 return (v);
87 90 }
88 91
89 92 /*
90 93 * Compute the hash of the full (remote) path name
91 94 * using the three parts supplied separately.
92 95 */
93 96 uint32_t
94 97 smbfs_gethash(const char *rpath, int rplen)
95 98 {
96 99 uint32_t v;
97 100
98 101 v = smbfs_hash(FNV1_32_INIT, rpath, rplen);
99 102 return (v);
100 103 }
101 104
102 105 /*
103 106 * Like smbfs_gethash, but optimized a little by
104 107 * starting with the directory hash.
105 108 */
106 109 uint32_t
107 110 smbfs_getino(struct smbnode *dnp, const char *name, int nmlen)
108 111 {
109 112 uint32_t ino;
110 113 char sep;
111 114
112 115 /* Start with directory hash */
113 116 ino = (uint32_t)dnp->n_ino;
114 117
115 118 /* separator (maybe) */
116 119 sep = SMBFS_DNP_SEP(dnp);
117 120 if (sep)
118 121 ino = smbfs_hash(ino, &sep, 1);
119 122
120 123 /* Now hash this component. */
121 124 ino = smbfs_hash(ino, name, nmlen);
122 125
123 126 return (ino);
124 127 }
125 128
126 129 /*
127 130 * Allocate and copy a string of passed length.
128 131 * The passed length does NOT include the null.
129 132 */
130 133 char *
131 134 smbfs_name_alloc(const char *name, int nmlen)
132 135 {
133 136 char *cp;
134 137
135 138 cp = kmem_alloc(nmlen + 1, KM_SLEEP);
136 139 bcopy(name, cp, nmlen);
137 140 cp[nmlen] = 0;
138 141
139 142 return (cp);
140 143 }
141 144
142 145 /*
143 146 * Free string from smbfs_name_alloc(). Again,
144 147 * the passed length does NOT include the null.
145 148 */
146 149 void
147 150 smbfs_name_free(const char *name, int nmlen)
148 151 {
149 152 kmem_free((char *)name, nmlen + 1);
150 153 }
151 154
152 155 /*
153 156 * smbfs_nget()
154 157 *
155 158 * Find or create a node under some directory node.
156 159 */
157 160 int
158 161 smbfs_nget(vnode_t *dvp, const char *name, int nmlen,
159 162 struct smbfattr *fap, vnode_t **vpp)
160 163 {
161 164 struct smbnode *dnp = VTOSMB(dvp);
162 165 struct smbnode *np;
163 166 vnode_t *vp;
164 167 char sep;
165 168
166 169 ASSERT(fap != NULL);
167 170 *vpp = NULL;
168 171
169 172 /* Don't expect "" or "." or ".." here anymore. */
170 173 if (nmlen == 0 || (nmlen == 1 && name[0] == '.') ||
171 174 (nmlen == 2 && name[0] == '.' && name[1] == '.')) {
172 175 return (EINVAL);
173 176 }
174 177 sep = SMBFS_DNP_SEP(dnp);
175 178
176 179 /* Find or create the node. */
177 180 np = smbfs_node_findcreate(dnp->n_mount,
178 181 dnp->n_rpath, dnp->n_rplen,
179 182 name, nmlen, sep, fap);
180 183
181 184 /*
182 185 * We should have np now, because we passed
183 186 * fap != NULL to smbfs_node_findcreate.
184 187 */
185 188 ASSERT(np != NULL);
186 189 vp = SMBTOV(np);
187 190
188 191 /*
189 192 * Files in an XATTR dir are also XATTR.
190 193 */
191 194 if (dnp->n_flag & N_XATTR) {
192 195 mutex_enter(&np->r_statelock);
193 196 np->n_flag |= N_XATTR;
194 197 mutex_exit(&np->r_statelock);
|
↓ open down ↓ |
142 lines elided |
↑ open up ↑ |
195 198 }
196 199
197 200 /* BSD symlink hack removed (smb_symmagic) */
198 201
199 202 *vpp = vp;
200 203
201 204 return (0);
202 205 }
203 206
204 207 /*
205 - * smbfs_attrcache_enter, smbfs_attrcache_lookup replaced by
206 - * code more closely resembling NFS. See smbfs_client.c
207 - */
208 -
209 -/*
210 208 * Update the local notion of the mtime of some directory.
211 209 * See comments re. r_mtime in smbfs_node.h
212 210 */
213 211 void
214 212 smbfs_attr_touchdir(struct smbnode *dnp)
215 213 {
216 214
217 215 mutex_enter(&dnp->r_statelock);
218 216
219 217 /*
220 218 * Now that we keep the client's notion of mtime
221 219 * separately from the server, this is easy.
222 220 */
223 221 dnp->r_mtime = gethrtime();
224 222
225 223 /*
226 224 * Invalidate the cache, so that we go to the wire
227 225 * to check that the server doesn't have a better
228 226 * timestamp next time we care.
229 227 */
230 228 smbfs_attrcache_rm_locked(dnp);
231 229 mutex_exit(&dnp->r_statelock);
232 230 }
233 231
234 232 void
235 233 smbfs_attrcache_remove(struct smbnode *np)
236 234 {
237 235 mutex_enter(&np->r_statelock);
238 236 /* smbfs_attrcache_rm_locked(np); */
239 237 np->r_attrtime = gethrtime();
240 238 mutex_exit(&np->r_statelock);
241 239 }
242 240
243 241 /* See smbfs_node.h */
244 242 #undef smbfs_attrcache_rm_locked
245 243 void
246 244 smbfs_attrcache_rm_locked(struct smbnode *np)
247 245 {
248 246 ASSERT(MUTEX_HELD(&np->r_statelock));
249 247 np->r_attrtime = gethrtime();
250 248 }
|
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX