author | Matthew Ahrens <mahrens@delphix.com> |
Sat, 30 Jun 2012 13:00:47 -0700 | |
changeset 13743 | 95aba6e49b9f |
parent 13700 | 2889e2596bd6 |
child 13869 | 921a99998bb4 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
22 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
13682
e7836650181b
1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents:
12798
diff
changeset
|
23 |
* Copyright (c) 2012 by Delphix. All rights reserved. |
789 | 24 |
*/ |
25 |
||
26 |
#include <assert.h> |
|
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
27 |
#include <fcntl.h> |
789 | 28 |
#include <poll.h> |
29 |
#include <stdio.h> |
|
30 |
#include <stdlib.h> |
|
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
31 |
#include <string.h> |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
32 |
#include <zlib.h> |
789 | 33 |
#include <sys/spa.h> |
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
34 |
#include <sys/stat.h> |
789 | 35 |
#include <sys/processor.h> |
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
36 |
#include <sys/zfs_context.h> |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
37 |
#include <sys/zmod.h> |
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
38 |
#include <sys/utsname.h> |
8662
18153249ee93
PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents:
7837
diff
changeset
|
39 |
#include <sys/systeminfo.h> |
2856 | 40 |
|
789 | 41 |
/* |
42 |
* Emulation of kernel services in userland. |
|
43 |
*/ |
|
44 |
||
11726
9686f6127423
6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents:
11173
diff
changeset
|
45 |
int aok; |
789 | 46 |
uint64_t physmem; |
47 |
vnode_t *rootdir = (vnode_t *)0xabcd1234; |
|
8662
18153249ee93
PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents:
7837
diff
changeset
|
48 |
char hw_serial[HW_HOSTID_LEN]; |
13682
e7836650181b
1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents:
12798
diff
changeset
|
49 |
vmem_t *zio_arena = NULL; |
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
50 |
|
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
51 |
struct utsname utsname = { |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
52 |
"userland", "libzpool", "1", "1", "na" |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
53 |
}; |
789 | 54 |
|
11173
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
11066
diff
changeset
|
55 |
/* this only exists to have its address taken */ |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
11066
diff
changeset
|
56 |
struct proc p0; |
87f3734e64df
6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
11066
diff
changeset
|
57 |
|
789 | 58 |
/* |
59 |
* ========================================================================= |
|
60 |
* threads |
|
61 |
* ========================================================================= |
|
62 |
*/ |
|
63 |
/*ARGSUSED*/ |
|
64 |
kthread_t * |
|
65 |
zk_thread_create(void (*func)(), void *arg) |
|
66 |
{ |
|
67 |
thread_t tid; |
|
68 |
||
69 |
VERIFY(thr_create(0, 0, (void *(*)(void *))func, arg, THR_DETACHED, |
|
70 |
&tid) == 0); |
|
71 |
||
72 |
return ((void *)(uintptr_t)tid); |
|
73 |
} |
|
74 |
||
75 |
/* |
|
76 |
* ========================================================================= |
|
3403 | 77 |
* kstats |
78 |
* ========================================================================= |
|
79 |
*/ |
|
80 |
/*ARGSUSED*/ |
|
81 |
kstat_t * |
|
82 |
kstat_create(char *module, int instance, char *name, char *class, |
|
83 |
uchar_t type, ulong_t ndata, uchar_t ks_flag) |
|
84 |
{ |
|
85 |
return (NULL); |
|
86 |
} |
|
87 |
||
88 |
/*ARGSUSED*/ |
|
89 |
void |
|
90 |
kstat_install(kstat_t *ksp) |
|
91 |
{} |
|
92 |
||
93 |
/*ARGSUSED*/ |
|
94 |
void |
|
95 |
kstat_delete(kstat_t *ksp) |
|
96 |
{} |
|
97 |
||
98 |
/* |
|
99 |
* ========================================================================= |
|
789 | 100 |
* mutexes |
101 |
* ========================================================================= |
|
102 |
*/ |
|
103 |
void |
|
104 |
zmutex_init(kmutex_t *mp) |
|
105 |
{ |
|
106 |
mp->m_owner = NULL; |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
107 |
mp->initialized = B_TRUE; |
789 | 108 |
(void) _mutex_init(&mp->m_lock, USYNC_THREAD, NULL); |
109 |
} |
|
110 |
||
111 |
void |
|
112 |
zmutex_destroy(kmutex_t *mp) |
|
113 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
114 |
ASSERT(mp->initialized == B_TRUE); |
789 | 115 |
ASSERT(mp->m_owner == NULL); |
116 |
(void) _mutex_destroy(&(mp)->m_lock); |
|
117 |
mp->m_owner = (void *)-1UL; |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
118 |
mp->initialized = B_FALSE; |
789 | 119 |
} |
120 |
||
121 |
void |
|
122 |
mutex_enter(kmutex_t *mp) |
|
123 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
124 |
ASSERT(mp->initialized == B_TRUE); |
789 | 125 |
ASSERT(mp->m_owner != (void *)-1UL); |
126 |
ASSERT(mp->m_owner != curthread); |
|
2856 | 127 |
VERIFY(mutex_lock(&mp->m_lock) == 0); |
789 | 128 |
ASSERT(mp->m_owner == NULL); |
129 |
mp->m_owner = curthread; |
|
130 |
} |
|
131 |
||
132 |
int |
|
133 |
mutex_tryenter(kmutex_t *mp) |
|
134 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
135 |
ASSERT(mp->initialized == B_TRUE); |
789 | 136 |
ASSERT(mp->m_owner != (void *)-1UL); |
137 |
if (0 == mutex_trylock(&mp->m_lock)) { |
|
138 |
ASSERT(mp->m_owner == NULL); |
|
139 |
mp->m_owner = curthread; |
|
140 |
return (1); |
|
141 |
} else { |
|
142 |
return (0); |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
void |
|
147 |
mutex_exit(kmutex_t *mp) |
|
148 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
149 |
ASSERT(mp->initialized == B_TRUE); |
789 | 150 |
ASSERT(mutex_owner(mp) == curthread); |
151 |
mp->m_owner = NULL; |
|
2856 | 152 |
VERIFY(mutex_unlock(&mp->m_lock) == 0); |
789 | 153 |
} |
154 |
||
155 |
void * |
|
156 |
mutex_owner(kmutex_t *mp) |
|
157 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
158 |
ASSERT(mp->initialized == B_TRUE); |
789 | 159 |
return (mp->m_owner); |
160 |
} |
|
161 |
||
162 |
/* |
|
163 |
* ========================================================================= |
|
164 |
* rwlocks |
|
165 |
* ========================================================================= |
|
166 |
*/ |
|
167 |
/*ARGSUSED*/ |
|
168 |
void |
|
169 |
rw_init(krwlock_t *rwlp, char *name, int type, void *arg) |
|
170 |
{ |
|
171 |
rwlock_init(&rwlp->rw_lock, USYNC_THREAD, NULL); |
|
172 |
rwlp->rw_owner = NULL; |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
173 |
rwlp->initialized = B_TRUE; |
789 | 174 |
} |
175 |
||
176 |
void |
|
177 |
rw_destroy(krwlock_t *rwlp) |
|
178 |
{ |
|
179 |
rwlock_destroy(&rwlp->rw_lock); |
|
180 |
rwlp->rw_owner = (void *)-1UL; |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
181 |
rwlp->initialized = B_FALSE; |
789 | 182 |
} |
183 |
||
184 |
void |
|
185 |
rw_enter(krwlock_t *rwlp, krw_t rw) |
|
186 |
{ |
|
187 |
ASSERT(!RW_LOCK_HELD(rwlp)); |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
188 |
ASSERT(rwlp->initialized == B_TRUE); |
789 | 189 |
ASSERT(rwlp->rw_owner != (void *)-1UL); |
190 |
ASSERT(rwlp->rw_owner != curthread); |
|
191 |
||
192 |
if (rw == RW_READER) |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
193 |
VERIFY(rw_rdlock(&rwlp->rw_lock) == 0); |
789 | 194 |
else |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
195 |
VERIFY(rw_wrlock(&rwlp->rw_lock) == 0); |
789 | 196 |
|
197 |
rwlp->rw_owner = curthread; |
|
198 |
} |
|
199 |
||
200 |
void |
|
201 |
rw_exit(krwlock_t *rwlp) |
|
202 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
203 |
ASSERT(rwlp->initialized == B_TRUE); |
789 | 204 |
ASSERT(rwlp->rw_owner != (void *)-1UL); |
205 |
||
206 |
rwlp->rw_owner = NULL; |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
207 |
VERIFY(rw_unlock(&rwlp->rw_lock) == 0); |
789 | 208 |
} |
209 |
||
210 |
int |
|
211 |
rw_tryenter(krwlock_t *rwlp, krw_t rw) |
|
212 |
{ |
|
213 |
int rv; |
|
214 |
||
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
215 |
ASSERT(rwlp->initialized == B_TRUE); |
789 | 216 |
ASSERT(rwlp->rw_owner != (void *)-1UL); |
217 |
||
218 |
if (rw == RW_READER) |
|
219 |
rv = rw_tryrdlock(&rwlp->rw_lock); |
|
220 |
else |
|
221 |
rv = rw_trywrlock(&rwlp->rw_lock); |
|
222 |
||
223 |
if (rv == 0) { |
|
224 |
rwlp->rw_owner = curthread; |
|
225 |
return (1); |
|
226 |
} |
|
227 |
||
228 |
return (0); |
|
229 |
} |
|
230 |
||
231 |
/*ARGSUSED*/ |
|
232 |
int |
|
233 |
rw_tryupgrade(krwlock_t *rwlp) |
|
234 |
{ |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4543
diff
changeset
|
235 |
ASSERT(rwlp->initialized == B_TRUE); |
789 | 236 |
ASSERT(rwlp->rw_owner != (void *)-1UL); |
237 |
||
238 |
return (0); |
|
239 |
} |
|
240 |
||
241 |
/* |
|
242 |
* ========================================================================= |
|
243 |
* condition variables |
|
244 |
* ========================================================================= |
|
245 |
*/ |
|
246 |
/*ARGSUSED*/ |
|
247 |
void |
|
248 |
cv_init(kcondvar_t *cv, char *name, int type, void *arg) |
|
249 |
{ |
|
2856 | 250 |
VERIFY(cond_init(cv, type, NULL) == 0); |
789 | 251 |
} |
252 |
||
253 |
void |
|
254 |
cv_destroy(kcondvar_t *cv) |
|
255 |
{ |
|
2856 | 256 |
VERIFY(cond_destroy(cv) == 0); |
789 | 257 |
} |
258 |
||
259 |
void |
|
260 |
cv_wait(kcondvar_t *cv, kmutex_t *mp) |
|
261 |
{ |
|
262 |
ASSERT(mutex_owner(mp) == curthread); |
|
263 |
mp->m_owner = NULL; |
|
2856 | 264 |
int ret = cond_wait(cv, &mp->m_lock); |
265 |
VERIFY(ret == 0 || ret == EINTR); |
|
789 | 266 |
mp->m_owner = curthread; |
267 |
} |
|
268 |
||
269 |
clock_t |
|
270 |
cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime) |
|
271 |
{ |
|
272 |
int error; |
|
273 |
timestruc_t ts; |
|
274 |
clock_t delta; |
|
275 |
||
276 |
top: |
|
11066
cebb50cbe4f9
PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents:
10858
diff
changeset
|
277 |
delta = abstime - ddi_get_lbolt(); |
789 | 278 |
if (delta <= 0) |
279 |
return (-1); |
|
280 |
||
281 |
ts.tv_sec = delta / hz; |
|
282 |
ts.tv_nsec = (delta % hz) * (NANOSEC / hz); |
|
283 |
||
284 |
ASSERT(mutex_owner(mp) == curthread); |
|
285 |
mp->m_owner = NULL; |
|
286 |
error = cond_reltimedwait(cv, &mp->m_lock, &ts); |
|
287 |
mp->m_owner = curthread; |
|
288 |
||
289 |
if (error == ETIME) |
|
290 |
return (-1); |
|
291 |
||
292 |
if (error == EINTR) |
|
293 |
goto top; |
|
294 |
||
295 |
ASSERT(error == 0); |
|
296 |
||
297 |
return (1); |
|
298 |
} |
|
299 |
||
300 |
void |
|
301 |
cv_signal(kcondvar_t *cv) |
|
302 |
{ |
|
2856 | 303 |
VERIFY(cond_signal(cv) == 0); |
789 | 304 |
} |
305 |
||
306 |
void |
|
307 |
cv_broadcast(kcondvar_t *cv) |
|
308 |
{ |
|
2856 | 309 |
VERIFY(cond_broadcast(cv) == 0); |
789 | 310 |
} |
311 |
||
312 |
/* |
|
313 |
* ========================================================================= |
|
314 |
* vnode operations |
|
315 |
* ========================================================================= |
|
316 |
*/ |
|
317 |
/* |
|
318 |
* Note: for the xxxat() versions of these functions, we assume that the |
|
319 |
* starting vp is always rootdir (which is true for spa_directory.c, the only |
|
320 |
* ZFS consumer of these interfaces). We assert this is true, and then emulate |
|
321 |
* them by adding '/' in front of the path. |
|
322 |
*/ |
|
323 |
||
324 |
/*ARGSUSED*/ |
|
325 |
int |
|
326 |
vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3) |
|
327 |
{ |
|
328 |
int fd; |
|
329 |
vnode_t *vp; |
|
330 |
int old_umask; |
|
331 |
char realpath[MAXPATHLEN]; |
|
332 |
struct stat64 st; |
|
333 |
||
334 |
/* |
|
335 |
* If we're accessing a real disk from userland, we need to use |
|
336 |
* the character interface to avoid caching. This is particularly |
|
337 |
* important if we're trying to look at a real in-kernel storage |
|
338 |
* pool from userland, e.g. via zdb, because otherwise we won't |
|
339 |
* see the changes occurring under the segmap cache. |
|
340 |
* On the other hand, the stupid character device returns zero |
|
341 |
* for its size. So -- gag -- we open the block device to get |
|
342 |
* its size, and remember it for subsequent VOP_GETATTR(). |
|
343 |
*/ |
|
344 |
if (strncmp(path, "/dev/", 5) == 0) { |
|
345 |
char *dsk; |
|
346 |
fd = open64(path, O_RDONLY); |
|
347 |
if (fd == -1) |
|
348 |
return (errno); |
|
349 |
if (fstat64(fd, &st) == -1) { |
|
350 |
close(fd); |
|
351 |
return (errno); |
|
352 |
} |
|
353 |
close(fd); |
|
354 |
(void) sprintf(realpath, "%s", path); |
|
355 |
dsk = strstr(path, "/dsk/"); |
|
356 |
if (dsk != NULL) |
|
357 |
(void) sprintf(realpath + (dsk - path) + 1, "r%s", |
|
358 |
dsk + 1); |
|
359 |
} else { |
|
360 |
(void) sprintf(realpath, "%s", path); |
|
361 |
if (!(flags & FCREAT) && stat64(realpath, &st) == -1) |
|
362 |
return (errno); |
|
363 |
} |
|
364 |
||
365 |
if (flags & FCREAT) |
|
366 |
old_umask = umask(0); |
|
367 |
||
368 |
/* |
|
369 |
* The construct 'flags - FREAD' conveniently maps combinations of |
|
370 |
* FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR. |
|
371 |
*/ |
|
372 |
fd = open64(realpath, flags - FREAD, mode); |
|
373 |
||
374 |
if (flags & FCREAT) |
|
375 |
(void) umask(old_umask); |
|
376 |
||
377 |
if (fd == -1) |
|
378 |
return (errno); |
|
379 |
||
380 |
if (fstat64(fd, &st) == -1) { |
|
381 |
close(fd); |
|
382 |
return (errno); |
|
383 |
} |
|
384 |
||
385 |
(void) fcntl(fd, F_SETFD, FD_CLOEXEC); |
|
386 |
||
387 |
*vpp = vp = umem_zalloc(sizeof (vnode_t), UMEM_NOFAIL); |
|
388 |
||
389 |
vp->v_fd = fd; |
|
390 |
vp->v_size = st.st_size; |
|
391 |
vp->v_path = spa_strdup(path); |
|
392 |
||
393 |
return (0); |
|
394 |
} |
|
395 |
||
5331 | 396 |
/*ARGSUSED*/ |
789 | 397 |
int |
398 |
vn_openat(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, |
|
5331 | 399 |
int x3, vnode_t *startvp, int fd) |
789 | 400 |
{ |
401 |
char *realpath = umem_alloc(strlen(path) + 2, UMEM_NOFAIL); |
|
402 |
int ret; |
|
403 |
||
404 |
ASSERT(startvp == rootdir); |
|
405 |
(void) sprintf(realpath, "/%s", path); |
|
406 |
||
5331 | 407 |
/* fd ignored for now, need if want to simulate nbmand support */ |
789 | 408 |
ret = vn_open(realpath, x1, flags, mode, vpp, x2, x3); |
409 |
||
410 |
umem_free(realpath, strlen(path) + 2); |
|
411 |
||
412 |
return (ret); |
|
413 |
} |
|
414 |
||
415 |
/*ARGSUSED*/ |
|
416 |
int |
|
417 |
vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset, |
|
418 |
int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp) |
|
419 |
{ |
|
420 |
ssize_t iolen, split; |
|
421 |
||
422 |
if (uio == UIO_READ) { |
|
423 |
iolen = pread64(vp->v_fd, addr, len, offset); |
|
424 |
} else { |
|
425 |
/* |
|
426 |
* To simulate partial disk writes, we split writes into two |
|
427 |
* system calls so that the process can be killed in between. |
|
428 |
*/ |
|
13700
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13682
diff
changeset
|
429 |
int sectors = len >> SPA_MINBLOCKSHIFT; |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13682
diff
changeset
|
430 |
split = (sectors > 0 ? rand() % sectors : 0) << |
2889e2596bd6
2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents:
13682
diff
changeset
|
431 |
SPA_MINBLOCKSHIFT; |
789 | 432 |
iolen = pwrite64(vp->v_fd, addr, split, offset); |
433 |
iolen += pwrite64(vp->v_fd, (char *)addr + split, |
|
434 |
len - split, offset + split); |
|
435 |
} |
|
436 |
||
437 |
if (iolen == -1) |
|
438 |
return (errno); |
|
439 |
if (residp) |
|
440 |
*residp = len - iolen; |
|
441 |
else if (iolen != len) |
|
442 |
return (EIO); |
|
443 |
return (0); |
|
444 |
} |
|
445 |
||
446 |
void |
|
447 |
vn_close(vnode_t *vp) |
|
448 |
{ |
|
449 |
close(vp->v_fd); |
|
450 |
spa_strfree(vp->v_path); |
|
451 |
umem_free(vp, sizeof (vnode_t)); |
|
452 |
} |
|
453 |
||
10850
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
454 |
/* |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
455 |
* At a minimum we need to update the size since vdev_reopen() |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
456 |
* will no longer call vn_openat(). |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
457 |
*/ |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
458 |
int |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
459 |
fop_getattr(vnode_t *vp, vattr_t *vap) |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
460 |
{ |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
461 |
struct stat64 st; |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
462 |
|
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
463 |
if (fstat64(vp->v_fd, &st) == -1) { |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
464 |
close(vp->v_fd); |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
465 |
return (errno); |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
466 |
} |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
467 |
|
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
468 |
vap->va_size = st.st_size; |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
469 |
return (0); |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
470 |
} |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10612
diff
changeset
|
471 |
|
789 | 472 |
#ifdef ZFS_DEBUG |
473 |
||
474 |
/* |
|
475 |
* ========================================================================= |
|
476 |
* Figure out which debugging statements to print |
|
477 |
* ========================================================================= |
|
478 |
*/ |
|
479 |
||
480 |
static char *dprintf_string; |
|
481 |
static int dprintf_print_all; |
|
482 |
||
483 |
int |
|
484 |
dprintf_find_string(const char *string) |
|
485 |
{ |
|
486 |
char *tmp_str = dprintf_string; |
|
487 |
int len = strlen(string); |
|
488 |
||
489 |
/* |
|
490 |
* Find out if this is a string we want to print. |
|
491 |
* String format: file1.c,function_name1,file2.c,file3.c |
|
492 |
*/ |
|
493 |
||
494 |
while (tmp_str != NULL) { |
|
495 |
if (strncmp(tmp_str, string, len) == 0 && |
|
496 |
(tmp_str[len] == ',' || tmp_str[len] == '\0')) |
|
497 |
return (1); |
|
498 |
tmp_str = strchr(tmp_str, ','); |
|
499 |
if (tmp_str != NULL) |
|
500 |
tmp_str++; /* Get rid of , */ |
|
501 |
} |
|
502 |
return (0); |
|
503 |
} |
|
504 |
||
505 |
void |
|
506 |
dprintf_setup(int *argc, char **argv) |
|
507 |
{ |
|
508 |
int i, j; |
|
509 |
||
510 |
/* |
|
511 |
* Debugging can be specified two ways: by setting the |
|
512 |
* environment variable ZFS_DEBUG, or by including a |
|
513 |
* "debug=..." argument on the command line. The command |
|
514 |
* line setting overrides the environment variable. |
|
515 |
*/ |
|
516 |
||
517 |
for (i = 1; i < *argc; i++) { |
|
518 |
int len = strlen("debug="); |
|
519 |
/* First look for a command line argument */ |
|
520 |
if (strncmp("debug=", argv[i], len) == 0) { |
|
521 |
dprintf_string = argv[i] + len; |
|
522 |
/* Remove from args */ |
|
523 |
for (j = i; j < *argc; j++) |
|
524 |
argv[j] = argv[j+1]; |
|
525 |
argv[j] = NULL; |
|
526 |
(*argc)--; |
|
527 |
} |
|
528 |
} |
|
529 |
||
530 |
if (dprintf_string == NULL) { |
|
531 |
/* Look for ZFS_DEBUG environment variable */ |
|
532 |
dprintf_string = getenv("ZFS_DEBUG"); |
|
533 |
} |
|
534 |
||
535 |
/* |
|
536 |
* Are we just turning on all debugging? |
|
537 |
*/ |
|
538 |
if (dprintf_find_string("on")) |
|
539 |
dprintf_print_all = 1; |
|
540 |
} |
|
541 |
||
542 |
/* |
|
543 |
* ========================================================================= |
|
544 |
* debug printfs |
|
545 |
* ========================================================================= |
|
546 |
*/ |
|
547 |
void |
|
548 |
__dprintf(const char *file, const char *func, int line, const char *fmt, ...) |
|
549 |
{ |
|
550 |
const char *newfile; |
|
551 |
va_list adx; |
|
552 |
||
553 |
/* |
|
554 |
* Get rid of annoying "../common/" prefix to filename. |
|
555 |
*/ |
|
556 |
newfile = strrchr(file, '/'); |
|
557 |
if (newfile != NULL) { |
|
558 |
newfile = newfile + 1; /* Get rid of leading / */ |
|
559 |
} else { |
|
560 |
newfile = file; |
|
561 |
} |
|
562 |
||
563 |
if (dprintf_print_all || |
|
564 |
dprintf_find_string(newfile) || |
|
565 |
dprintf_find_string(func)) { |
|
566 |
/* Print out just the function name if requested */ |
|
567 |
flockfile(stdout); |
|
568 |
if (dprintf_find_string("pid")) |
|
569 |
(void) printf("%d ", getpid()); |
|
570 |
if (dprintf_find_string("tid")) |
|
571 |
(void) printf("%u ", thr_self()); |
|
572 |
if (dprintf_find_string("cpu")) |
|
573 |
(void) printf("%u ", getcpuid()); |
|
574 |
if (dprintf_find_string("time")) |
|
575 |
(void) printf("%llu ", gethrtime()); |
|
576 |
if (dprintf_find_string("long")) |
|
577 |
(void) printf("%s, line %d: ", newfile, line); |
|
578 |
(void) printf("%s: ", func); |
|
579 |
va_start(adx, fmt); |
|
580 |
(void) vprintf(fmt, adx); |
|
581 |
va_end(adx); |
|
582 |
funlockfile(stdout); |
|
583 |
} |
|
584 |
} |
|
585 |
||
586 |
#endif /* ZFS_DEBUG */ |
|
587 |
||
588 |
/* |
|
589 |
* ========================================================================= |
|
590 |
* cmn_err() and panic() |
|
591 |
* ========================================================================= |
|
592 |
*/ |
|
593 |
static char ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" }; |
|
594 |
static char ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" }; |
|
595 |
||
596 |
void |
|
597 |
vpanic(const char *fmt, va_list adx) |
|
598 |
{ |
|
599 |
(void) fprintf(stderr, "error: "); |
|
600 |
(void) vfprintf(stderr, fmt, adx); |
|
601 |
(void) fprintf(stderr, "\n"); |
|
602 |
||
603 |
abort(); /* think of it as a "user-level crash dump" */ |
|
604 |
} |
|
605 |
||
606 |
void |
|
607 |
panic(const char *fmt, ...) |
|
608 |
{ |
|
609 |
va_list adx; |
|
610 |
||
611 |
va_start(adx, fmt); |
|
612 |
vpanic(fmt, adx); |
|
613 |
va_end(adx); |
|
614 |
} |
|
615 |
||
3713 | 616 |
void |
617 |
vcmn_err(int ce, const char *fmt, va_list adx) |
|
618 |
{ |
|
619 |
if (ce == CE_PANIC) |
|
620 |
vpanic(fmt, adx); |
|
621 |
if (ce != CE_NOTE) { /* suppress noise in userland stress testing */ |
|
622 |
(void) fprintf(stderr, "%s", ce_prefix[ce]); |
|
623 |
(void) vfprintf(stderr, fmt, adx); |
|
624 |
(void) fprintf(stderr, "%s", ce_suffix[ce]); |
|
625 |
} |
|
626 |
} |
|
627 |
||
789 | 628 |
/*PRINTFLIKE2*/ |
629 |
void |
|
630 |
cmn_err(int ce, const char *fmt, ...) |
|
631 |
{ |
|
632 |
va_list adx; |
|
633 |
||
634 |
va_start(adx, fmt); |
|
3713 | 635 |
vcmn_err(ce, fmt, adx); |
789 | 636 |
va_end(adx); |
637 |
} |
|
638 |
||
639 |
/* |
|
640 |
* ========================================================================= |
|
1544 | 641 |
* kobj interfaces |
642 |
* ========================================================================= |
|
643 |
*/ |
|
644 |
struct _buf * |
|
645 |
kobj_open_file(char *name) |
|
646 |
{ |
|
647 |
struct _buf *file; |
|
648 |
vnode_t *vp; |
|
649 |
||
650 |
/* set vp as the _fd field of the file */ |
|
5331 | 651 |
if (vn_openat(name, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0, rootdir, |
652 |
-1) != 0) |
|
1544 | 653 |
return ((void *)-1UL); |
654 |
||
655 |
file = umem_zalloc(sizeof (struct _buf), UMEM_NOFAIL); |
|
656 |
file->_fd = (intptr_t)vp; |
|
657 |
return (file); |
|
658 |
} |
|
659 |
||
660 |
int |
|
661 |
kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off) |
|
662 |
{ |
|
663 |
ssize_t resid; |
|
664 |
||
665 |
vn_rdwr(UIO_READ, (vnode_t *)file->_fd, buf, size, (offset_t)off, |
|
666 |
UIO_SYSSPACE, 0, 0, 0, &resid); |
|
667 |
||
3912 | 668 |
return (size - resid); |
1544 | 669 |
} |
670 |
||
671 |
void |
|
672 |
kobj_close_file(struct _buf *file) |
|
673 |
{ |
|
674 |
vn_close((vnode_t *)file->_fd); |
|
675 |
umem_free(file, sizeof (struct _buf)); |
|
676 |
} |
|
677 |
||
678 |
int |
|
3912 | 679 |
kobj_get_filesize(struct _buf *file, uint64_t *size) |
1544 | 680 |
{ |
681 |
struct stat64 st; |
|
3912 | 682 |
vnode_t *vp = (vnode_t *)file->_fd; |
683 |
||
1544 | 684 |
if (fstat64(vp->v_fd, &st) == -1) { |
685 |
vn_close(vp); |
|
686 |
return (errno); |
|
687 |
} |
|
3912 | 688 |
*size = st.st_size; |
1544 | 689 |
return (0); |
690 |
} |
|
691 |
||
692 |
/* |
|
693 |
* ========================================================================= |
|
789 | 694 |
* misc routines |
695 |
* ========================================================================= |
|
696 |
*/ |
|
697 |
||
698 |
void |
|
699 |
delay(clock_t ticks) |
|
700 |
{ |
|
701 |
poll(0, 0, ticks * (1000 / hz)); |
|
702 |
} |
|
703 |
||
704 |
/* |
|
705 |
* Find highest one bit set. |
|
706 |
* Returns bit number + 1 of highest bit that is set, otherwise returns 0. |
|
707 |
* High order bit is 31 (or 63 in _LP64 kernel). |
|
708 |
*/ |
|
709 |
int |
|
710 |
highbit(ulong_t i) |
|
711 |
{ |
|
712 |
register int h = 1; |
|
713 |
||
714 |
if (i == 0) |
|
715 |
return (0); |
|
716 |
#ifdef _LP64 |
|
717 |
if (i & 0xffffffff00000000ul) { |
|
718 |
h += 32; i >>= 32; |
|
719 |
} |
|
720 |
#endif |
|
721 |
if (i & 0xffff0000) { |
|
722 |
h += 16; i >>= 16; |
|
723 |
} |
|
724 |
if (i & 0xff00) { |
|
725 |
h += 8; i >>= 8; |
|
726 |
} |
|
727 |
if (i & 0xf0) { |
|
728 |
h += 4; i >>= 4; |
|
729 |
} |
|
730 |
if (i & 0xc) { |
|
731 |
h += 2; i >>= 2; |
|
732 |
} |
|
733 |
if (i & 0x2) { |
|
734 |
h += 1; |
|
735 |
} |
|
736 |
return (h); |
|
737 |
} |
|
738 |
||
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
739 |
static int random_fd = -1, urandom_fd = -1; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
740 |
|
789 | 741 |
static int |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
742 |
random_get_bytes_common(uint8_t *ptr, size_t len, int fd) |
789 | 743 |
{ |
744 |
size_t resid = len; |
|
745 |
ssize_t bytes; |
|
746 |
||
747 |
ASSERT(fd != -1); |
|
748 |
||
749 |
while (resid != 0) { |
|
750 |
bytes = read(fd, ptr, resid); |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
751 |
ASSERT3S(bytes, >=, 0); |
789 | 752 |
ptr += bytes; |
753 |
resid -= bytes; |
|
754 |
} |
|
755 |
||
756 |
return (0); |
|
757 |
} |
|
758 |
||
759 |
int |
|
760 |
random_get_bytes(uint8_t *ptr, size_t len) |
|
761 |
{ |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
762 |
return (random_get_bytes_common(ptr, len, random_fd)); |
789 | 763 |
} |
764 |
||
765 |
int |
|
766 |
random_get_pseudo_bytes(uint8_t *ptr, size_t len) |
|
767 |
{ |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
768 |
return (random_get_bytes_common(ptr, len, urandom_fd)); |
789 | 769 |
} |
770 |
||
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
771 |
int |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
772 |
ddi_strtoul(const char *hw_serial, char **nptr, int base, unsigned long *result) |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
773 |
{ |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
774 |
char *end; |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
775 |
|
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
776 |
*result = strtoul(hw_serial, &end, base); |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
777 |
if (*result == 0) |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
778 |
return (errno); |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
779 |
return (0); |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
780 |
} |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
781 |
|
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
782 |
int |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
783 |
ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
784 |
{ |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
785 |
char *end; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
786 |
|
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
787 |
*result = strtoull(str, &end, base); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
788 |
if (*result == 0) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
789 |
return (errno); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
790 |
return (0); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
791 |
} |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11726
diff
changeset
|
792 |
|
789 | 793 |
/* |
794 |
* ========================================================================= |
|
795 |
* kernel emulation setup & teardown |
|
796 |
* ========================================================================= |
|
797 |
*/ |
|
798 |
static int |
|
799 |
umem_out_of_memory(void) |
|
800 |
{ |
|
801 |
char errmsg[] = "out of memory -- generating core dump\n"; |
|
802 |
||
803 |
write(fileno(stderr), errmsg, sizeof (errmsg)); |
|
804 |
abort(); |
|
805 |
return (0); |
|
806 |
} |
|
807 |
||
808 |
void |
|
809 |
kernel_init(int mode) |
|
810 |
{ |
|
811 |
umem_nofail_callback(umem_out_of_memory); |
|
812 |
||
813 |
physmem = sysconf(_SC_PHYS_PAGES); |
|
814 |
||
815 |
dprintf("physmem = %llu pages (%.2f GB)\n", physmem, |
|
816 |
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30)); |
|
817 |
||
10858
9efff268b959
6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents:
10850
diff
changeset
|
818 |
(void) snprintf(hw_serial, sizeof (hw_serial), "%ld", |
9efff268b959
6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents:
10850
diff
changeset
|
819 |
(mode & FWRITE) ? gethostid() : 0); |
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
820 |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
821 |
VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
822 |
VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
823 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
6689
diff
changeset
|
824 |
system_taskq_init(); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
6689
diff
changeset
|
825 |
|
789 | 826 |
spa_init(mode); |
827 |
} |
|
828 |
||
829 |
void |
|
830 |
kernel_fini(void) |
|
831 |
{ |
|
832 |
spa_fini(); |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
833 |
|
10612
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10272
diff
changeset
|
834 |
system_taskq_fini(); |
89423355fa6f
6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents:
10272
diff
changeset
|
835 |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
836 |
close(random_fd); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
837 |
close(urandom_fd); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
838 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
839 |
random_fd = -1; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5331
diff
changeset
|
840 |
urandom_fd = -1; |
789 | 841 |
} |
3886
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
842 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
843 |
int |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
844 |
z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen) |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
845 |
{ |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
846 |
int ret; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
847 |
uLongf len = *dstlen; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
848 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
849 |
if ((ret = uncompress(dst, &len, src, srclen)) == Z_OK) |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
850 |
*dstlen = (size_t)len; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
851 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
852 |
return (ret); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
853 |
} |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
854 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
855 |
int |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
856 |
z_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen, |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
857 |
int level) |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
858 |
{ |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
859 |
int ret; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
860 |
uLongf len = *dstlen; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
861 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
862 |
if ((ret = compress2(dst, &len, src, srclen, level)) == Z_OK) |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
863 |
*dstlen = (size_t)len; |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
864 |
|
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
865 |
return (ret); |
3291401d66a6
6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents:
3713
diff
changeset
|
866 |
} |
4543 | 867 |
|
868 |
uid_t |
|
869 |
crgetuid(cred_t *cr) |
|
870 |
{ |
|
871 |
return (0); |
|
872 |
} |
|
873 |
||
13743
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13700
diff
changeset
|
874 |
uid_t |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13700
diff
changeset
|
875 |
crgetruid(cred_t *cr) |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13700
diff
changeset
|
876 |
{ |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13700
diff
changeset
|
877 |
return (0); |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13700
diff
changeset
|
878 |
} |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13700
diff
changeset
|
879 |
|
4543 | 880 |
gid_t |
881 |
crgetgid(cred_t *cr) |
|
882 |
{ |
|
883 |
return (0); |
|
884 |
} |
|
885 |
||
886 |
int |
|
887 |
crgetngroups(cred_t *cr) |
|
888 |
{ |
|
889 |
return (0); |
|
890 |
} |
|
891 |
||
892 |
gid_t * |
|
893 |
crgetgroups(cred_t *cr) |
|
894 |
{ |
|
895 |
return (NULL); |
|
896 |
} |
|
897 |
||
898 |
int |
|
899 |
zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr) |
|
900 |
{ |
|
901 |
return (0); |
|
902 |
} |
|
903 |
||
904 |
int |
|
905 |
zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr) |
|
906 |
{ |
|
907 |
return (0); |
|
908 |
} |
|
909 |
||
910 |
int |
|
911 |
zfs_secpolicy_destroy_perms(const char *name, cred_t *cr) |
|
912 |
{ |
|
913 |
return (0); |
|
914 |
} |
|
5959
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
915 |
|
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
916 |
ksiddomain_t * |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
917 |
ksid_lookupdomain(const char *dom) |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
918 |
{ |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
919 |
ksiddomain_t *kd; |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
920 |
|
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
921 |
kd = umem_zalloc(sizeof (ksiddomain_t), UMEM_NOFAIL); |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
922 |
kd->kd_name = spa_strdup(dom); |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
923 |
return (kd); |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
924 |
} |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
925 |
|
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
926 |
void |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
927 |
ksiddomain_rele(ksiddomain_t *ksid) |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
928 |
{ |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
929 |
spa_strfree(ksid->kd_name); |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
930 |
umem_free(ksid, sizeof (ksiddomain_t)); |
1e1904b8526d
6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents:
5688
diff
changeset
|
931 |
} |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
932 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
933 |
/* |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
934 |
* Do not change the length of the returned string; it must be freed |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
935 |
* with strfree(). |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
936 |
*/ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
937 |
char * |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
938 |
kmem_asprintf(const char *fmt, ...) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
939 |
{ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
940 |
int size; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
941 |
va_list adx; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
942 |
char *buf; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
943 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
944 |
va_start(adx, fmt); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
945 |
size = vsnprintf(NULL, 0, fmt, adx) + 1; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
946 |
va_end(adx); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
947 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
948 |
buf = kmem_alloc(size, KM_SLEEP); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
949 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
950 |
va_start(adx, fmt); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
951 |
size = vsnprintf(buf, size, fmt, adx); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
952 |
va_end(adx); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
953 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
954 |
return (buf); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8662
diff
changeset
|
955 |
} |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
956 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
957 |
/* ARGSUSED */ |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
958 |
int |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
959 |
zfs_onexit_fd_hold(int fd, minor_t *minorp) |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
960 |
{ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
961 |
*minorp = 0; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
962 |
return (0); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
963 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
964 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
965 |
/* ARGSUSED */ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
966 |
void |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
967 |
zfs_onexit_fd_rele(int fd) |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
968 |
{ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
969 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
970 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
971 |
/* ARGSUSED */ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
972 |
int |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
973 |
zfs_onexit_add_cb(minor_t minor, void (*func)(void *), void *data, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
974 |
uint64_t *action_handle) |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
975 |
{ |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
976 |
return (0); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
977 |
} |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
978 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
979 |
/* ARGSUSED */ |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
980 |
int |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
981 |
zfs_onexit_del_cb(minor_t minor, uint64_t action_handle, boolean_t fire) |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
982 |
{ |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
983 |
return (0); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
984 |
} |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
985 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
986 |
/* ARGSUSED */ |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
987 |
int |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
988 |
zfs_onexit_cb_data(minor_t minor, uint64_t action_handle, void **data) |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
989 |
{ |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
990 |
return (0); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
11935
diff
changeset
|
991 |
} |