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)
re #13613 rb4516 Tunables needs volatile keyword
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/sys/dnlc.h
+++ new/usr/src/uts/common/sys/dnlc.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
23 24 */
24 25
25 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 27 /* All Rights Reserved */
27 28
28 29 /*
29 30 * University Copyright- Copyright (c) 1982, 1986, 1988
30 31 * The Regents of the University of California
31 32 * All Rights Reserved
32 33 *
33 34 * University Acknowledgment- Portions of this document are derived from
34 35 * software developed by the University of California, Berkeley, and its
35 36 * contributors.
36 37 */
37 38
38 39 #ifndef _SYS_DNLC_H
39 40 #define _SYS_DNLC_H
40 41
41 42 #ifdef __cplusplus
42 43 extern "C" {
43 44 #endif
44 45
45 46 #include <sys/kstat.h>
46 47
47 48 /*
48 49 * DNLC - Directory name lookup cache.
49 50 * There are now two sorts of name caching:
50 51 *
51 52 * Standard dnlc: This original cache holds recent mappings
52 53 * of <directory vnode, name> to vnode mappings.
53 54 *
54 55 * Directory caches: Entire large directories can be cached, subject to
55 56 * memory availability and tunables. A directory cache
56 57 * anchor point must be provided in the xxnode for
57 58 * a directory.
58 59 */
59 60
60 61
61 62 /*
62 63 * Standard dnlc
63 64 * =============
64 65 */
65 66
66 67 /*
67 68 * This structure describes the elements in the cache of recent
68 69 * names looked up.
69 70 *
70 71 * Note namlen is a uchar_t to conserve space
71 72 * and alignment padding. The max length of any
72 73 * pathname component is defined as MAXNAMELEN
73 74 * which is 256 (including the terminating null).
74 75 * So provided this doesn't change, we don't include the null,
75 76 * we always use bcmp to compare strings, and we don't start
76 77 * storing full names, then we are ok. The space savings are worth it.
77 78 */
78 79 typedef struct ncache {
79 80 struct ncache *hash_next; /* hash chain, MUST BE FIRST */
80 81 struct ncache *hash_prev;
81 82 struct vnode *vp; /* vnode the name refers to */
82 83 struct vnode *dp; /* vnode of parent of name */
83 84 int hash; /* hash signature */
84 85 uchar_t namlen; /* length of name */
85 86 char name[1]; /* segment name - null terminated */
86 87 } ncache_t;
87 88
88 89 /*
89 90 * Hash table bucket structure of name cache entries for fast lookup.
90 91 */
91 92 typedef struct nc_hash {
92 93 ncache_t *hash_next;
93 94 ncache_t *hash_prev;
94 95 kmutex_t hash_lock;
95 96 } nc_hash_t;
96 97
97 98 /*
98 99 * Statistics on name cache
99 100 * Not protected by locks
100 101 */
101 102 /*
102 103 * ncstats has been deprecated, due to the integer size of the counters
103 104 * which can easily overflow in the dnlc.
104 105 * It is maintained (at some expense) for compatability.
105 106 * The preferred interface is the kstat accessible nc_stats below, ehich
106 107 * is actually shared with directory caching.
107 108 */
108 109 struct ncstats {
109 110 int hits; /* hits that we can really use */
110 111 int misses; /* cache misses */
111 112 int enters; /* number of enters done */
112 113 int dbl_enters; /* number of enters tried when already cached */
113 114 int long_enter; /* deprecated, no longer accounted */
114 115 int long_look; /* deprecated, no longer accounted */
115 116 int move_to_front; /* entry moved to front of hash chain */
116 117 int purges; /* number of purges of cache */
117 118 };
118 119
119 120 struct nc_stats {
120 121 kstat_named_t ncs_hits; /* cache hits */
121 122 kstat_named_t ncs_misses; /* cache misses */
122 123 kstat_named_t ncs_neg_hits; /* negative cache hits */
123 124 kstat_named_t ncs_enters; /* enters */
124 125 kstat_named_t ncs_dbl_enters; /* enters when entry already cached */
125 126 kstat_named_t ncs_purge_total; /* total entries prurged */
126 127 kstat_named_t ncs_purge_all; /* dnlc_purge() calls */
127 128 kstat_named_t ncs_purge_vp; /* dnlc_purge_vp() calls */
128 129 kstat_named_t ncs_purge_vfs; /* dnlc_purge_vfs() calls */
129 130 kstat_named_t ncs_purge_fs1; /* dnlc_purge_fs1() calls */
130 131 kstat_named_t ncs_pick_free; /* found a free ncache */
131 132 kstat_named_t ncs_pick_heur; /* found ncache w/ NULL vpages */
132 133 kstat_named_t ncs_pick_last; /* found last ncache on chain */
133 134
134 135 /* directory caching stats */
135 136
136 137 kstat_named_t ncs_dir_hits; /* dir cache hits */
137 138 kstat_named_t ncs_dir_misses; /* dir cache misses */
138 139 kstat_named_t ncs_cur_dirs; /* current # directories cached */
139 140 kstat_named_t ncs_dir_num_ents; /* current # entries cached */
140 141 kstat_named_t ncs_dirs_cached; /* total # directories cached */
141 142 kstat_named_t ncs_dir_start_nm; /* dir start no memory */
142 143 kstat_named_t ncs_dir_add_nm; /* add entry/space - no memory */
143 144 kstat_named_t ncs_dir_addabort; /* add entry/space - abort */
144 145 kstat_named_t ncs_dir_add_max; /* add entry/space - max exceeded */
145 146 kstat_named_t ncs_dir_reme_fai; /* remove entry fail */
146 147 kstat_named_t ncs_dir_rems_fai; /* remove space fail */
147 148 kstat_named_t ncs_dir_upd_fail; /* update space fail */
148 149 kstat_named_t ncs_dir_finipurg; /* fini purges */
149 150 kstat_named_t ncs_dir_rec_last; /* reclaim last */
150 151 kstat_named_t ncs_dir_recl_any; /* reclaim any */
151 152 };
152 153
153 154 /*
154 155 * The dnlc hashing function.
155 156 * Although really a kernel macro we export it to allow validation
156 157 * of ncache_t entries by mdb. Note, mdb can handle the ASSERT.
157 158 *
158 159 * 'hash' and 'namlen' must be l-values. A check is made to ensure
159 160 * the name length fits into an unsigned char (see ncache_t).
160 161 */
161 162 #define DNLCHASH(name, dvp, hash, namlen) \
|
↓ open down ↓ |
129 lines elided |
↑ open up ↑ |
162 163 { \
163 164 char Xc; \
164 165 const char *Xcp; \
165 166 hash = (int)((uintptr_t)(dvp)) >> 8; \
166 167 for (Xcp = (name); (Xc = *Xcp) != 0; Xcp++) \
167 168 (hash) = ((hash) << 4) + (hash) + Xc; \
168 169 ASSERT((Xcp - (name)) <= ((1 << NBBY) - 1)); \
169 170 (namlen) = Xcp - (name); \
170 171 }
171 172
172 -#if defined(_KERNEL)
173 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
173 174
174 175 #include <sys/vfs.h>
175 176 #include <sys/vnode.h>
176 177
177 -extern int ncsize; /* set in param_init() # of dnlc entries */
178 +extern volatile int ncsize; /* set in param_init() # of dnlc entries */
178 179 extern vnode_t negative_cache_vnode;
179 180 #define DNLC_NO_VNODE &negative_cache_vnode
180 181
181 182 void dnlc_init(void);
182 183 void dnlc_enter(vnode_t *, const char *, vnode_t *);
183 184 void dnlc_update(vnode_t *, const char *, vnode_t *);
184 185 vnode_t *dnlc_lookup(vnode_t *, const char *);
185 186 void dnlc_purge(void);
186 187 void dnlc_purge_vp(vnode_t *);
187 188 int dnlc_purge_vfsp(vfs_t *, int);
188 189 void dnlc_remove(vnode_t *, const char *);
189 190 int dnlc_fs_purge1(struct vnodeops *);
190 191 void dnlc_reduce_cache(void *);
191 192
192 193 #endif /* defined(_KERNEL) */
193 194
194 195
195 196 /*
196 197 * Directory caching interfaces
197 198 * ============================
198 199 */
199 200
200 201 /*
201 202 * Typically for large directories, the file names will be the same or
202 203 * at least similar lengths. So there's no point in anything more elaborate
203 204 * than a simple unordered linked list of free space entries.
204 205 * For small directories the name length distribution doesn't really matter.
205 206 */
206 207 typedef struct dcfree {
207 208 uint64_t df_handle; /* fs supplied handle */
208 209 struct dcfree *df_next; /* link to next free entry in bucket */
209 210 uint_t df_len; /* length of free entry */
210 211 } dcfree_t;
211 212
212 213 typedef struct dcentry {
213 214 uint64_t de_handle; /* fs supplied and returned data */
214 215 struct dcentry *de_next; /* link to next name entry in bucket */
215 216 int de_hash; /* hash signature */
216 217 uchar_t de_namelen; /* length of name excluding null */
217 218 char de_name[1]; /* null terminated name */
218 219 } dcentry_t;
219 220
220 221 typedef struct dircache {
221 222 struct dircache *dc_next; /* chain - for purge purposes */
222 223 struct dircache *dc_prev; /* chain - for purge purposes */
223 224 int64_t dc_actime; /* dir access time, from lbolt64 */
224 225 dcentry_t **dc_namehash; /* entry hash table pointer */
225 226 dcfree_t **dc_freehash; /* free entry hash table pointer */
226 227 uint_t dc_num_entries; /* no of named entries */
227 228 uint_t dc_num_free; /* no of free space entries */
228 229 uint_t dc_nhash_mask; /* name hash table size - 1 */
229 230 uint_t dc_fhash_mask; /* free space hash table size - 1 */
230 231 struct dcanchor *dc_anchor; /* back ptr to anchor */
231 232 boolean_t dc_complete; /* cache complete boolean */
232 233 } dircache_t;
233 234
234 235 typedef struct dcanchor {
235 236 void *dca_dircache; /* pointer to directory cache */
236 237 kmutex_t dca_lock; /* protects the directory cache */
237 238 } dcanchor_t;
238 239
239 240 /*
240 241 * Head struct for doubly linked chain of dircache_t
241 242 * The next and prev fields must match those of a dircache_t
242 243 */
243 244 typedef struct {
244 245 dircache_t *dch_next; /* next in chain */
245 246 dircache_t *dch_prev; /* prev in chain */
246 247 kmutex_t dch_lock; /* lock for the chain */
247 248 } dchead_t;
248 249
249 250
250 251 #if defined(_KERNEL)
251 252
252 253 /*
253 254 * Status returns from the directory cache interfaces
254 255 */
255 256 typedef enum {
256 257 DOK, /* operation sucessful */
257 258 DNOCACHE, /* there is no cache */
258 259 DFOUND, /* entry found */
259 260 DNOENT, /* no entry found */
260 261 DTOOBIG, /* exceeds tunable dnlc_max_dir_cache */
261 262 DNOMEM /* no memory */
262 263 } dcret_t;
263 264
264 265 /*
265 266 * dnlc_dir_start() requests that a directory be cached.
266 267 * This must be called initially to enable caching on a directory.
267 268 * After a successful call, directory entries and free space can be
268 269 * added (see below) until the directory is marked complete.
269 270 * "num_entries" is an estimate of the current number of
270 271 * directory entries. The request is rejected with DNOCACHE
271 272 * if num_entries falls below the tunable dnlc_dir_min_size (see
272 273 * below), and rejected with DTOOBIG if it's above dnlc_dir_max_size.
273 274 * Returns DOK, DNOCACHE, DTOOBIG, DNOMEM.
274 275 *
275 276 * Due to memory shortages, directory caches can be purged at
276 277 * any time. If the last directory cache is purged due to memory
277 278 * shortage, then the directory cache is marked internally
278 279 * as "no memory". Future returns will all be DNOCACHE until
279 280 * the next dnlc_start_dir() which will return DNOMEM once.
280 281 * This memory shortage may only be transient. It's up to the
281 282 * file system as to what to do about this condition, but an
282 283 * attempt to immediately re-build the cache will very likely
283 284 * lead to the same shortage of memory and a thrashing situation.
284 285 *
285 286 * It's file system policy as to when and what size directories to cache.
286 287 */
287 288 dcret_t dnlc_dir_start(dcanchor_t *dcap, uint_t num_entries);
288 289
289 290 /*
290 291 * dnlc_dir_add_entry() adds an entry (name and handle) into a
291 292 * partial or complete cache. "handle" is a file system specific
292 293 * quantity that is returned on calls to dnlc_dir_lookup() - see below.
293 294 * For example, "handle" for ufs holds the inumber and a directory
294 295 * entry offset. Returns DOK, DNOCACHE, DTOOBIG.
295 296 */
296 297 dcret_t dnlc_dir_add_entry(dcanchor_t *dcap, const char *name, uint64_t handle);
297 298
298 299 /*
299 300 * dnlc_dir_add_space adds free space (length and file system specific
300 301 * handle) into a partial or complete cache. "handle" is a file
301 302 * system specific quantity that is returned on calls to
302 303 * dnlc_dir_rem_space_by_len(). For example, "handle" for ufs holds
303 304 * the directory entry offset. Returns DOK, DNOCACHE, DTOOBIG.
304 305 */
305 306 dcret_t dnlc_dir_add_space(dcanchor_t *dcap, uint_t len, uint64_t handle);
306 307
307 308 /*
308 309 * dnlc_dir_complete() indicates the previously partial cache is now complete.
309 310 */
310 311 void dnlc_dir_complete(dcanchor_t *dcap);
311 312
312 313 /*
313 314 * dnlc_dir_purge() deletes a partial or complete directory cache
314 315 */
315 316 void dnlc_dir_purge(dcanchor_t *dcap);
316 317
317 318 /*
318 319 * dnlc_dir_lookup() lookups a file name in a directory cache
319 320 * and returns the file system handle specified on dnlc_dir_add_entry()
320 321 * in "handlep". Returns DFOUND, DNOENT, DNOCACHE.
321 322 */
322 323 dcret_t dnlc_dir_lookup(dcanchor_t *dcap, const char *name, uint64_t *handlep);
323 324
324 325 /*
325 326 * dnlc_dir_update() amends the handle for an entry in a directory cache
326 327 * "handle" is the new file system specific handle for the file "name".
327 328 * Returns DFOUND, DNOENT, DNOCACHE.
328 329 */
329 330 dcret_t dnlc_dir_update(dcanchor_t *dcap, const char *name, uint64_t handle);
330 331
331 332 /*
332 333 * dnlc_dir_rem_entry() removes an entry form a directory cache.
333 334 * Returns the handle if "handlep" non null.
334 335 * Returns DFOUND, DNOENT, DNOCACHE.
335 336 */
336 337 dcret_t dnlc_dir_rem_entry(dcanchor_t *dcap, const char *name,
337 338 uint64_t *handlep);
338 339
339 340 /*
340 341 * dnlc_dir_rem_space_by_len() looks up and returns free space in a
341 342 * directory cache of at least the given "len". Returns in "handlep"
342 343 * the handle supplied when adding the free space in dnlc_dir_add_space().
343 344 * Returns DFOUND, DNOENT, DNOCACHE.
344 345 */
345 346 dcret_t dnlc_dir_rem_space_by_len(dcanchor_t *dcap, uint_t len,
346 347 uint64_t *handlep);
347 348
348 349 /*
349 350 * dnlc_dir_rem_space_by_handle() looks up and removes the free space in
350 351 * a directory cache with the given handle. Returns DFOUND, DNOENT, DNOCACHE.
351 352 */
352 353 dcret_t dnlc_dir_rem_space_by_handle(dcanchor_t *dcap, uint64_t handle);
353 354
354 355 /*
355 356 * dnlc_dir_init() initialises a directory anchor
356 357 */
357 358 #define dnlc_dir_init(dcap) { \
358 359 (dcap)->dca_dircache = NULL; \
359 360 mutex_init(&(dcap)->dca_lock, NULL, MUTEX_DEFAULT, NULL); }
360 361
361 362 /*
362 363 * dnlc_dir_fini() is called to indicate the anchor is no longer used.
363 364 * It ensures there's no directory cache and mutex_destroys the lock
364 365 */
365 366 void dnlc_dir_fini(dcanchor_t *dcap);
366 367
367 368 #endif /* defined(_KERNEL) */
368 369
369 370 #ifdef __cplusplus
370 371 }
371 372 #endif
372 373
373 374 #endif /* _SYS_DNLC_H */
|
↓ open down ↓ |
186 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX