4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
32 #include <sys/signal.h>
35 #include <sys/processor.h>
36 #include <sys/zfs_context.h>
37 #include <sys/utsname.h>
38 #include <sys/systeminfo.h>
41 * Emulation of kernel services in userland.
46 vnode_t
*rootdir
= (vnode_t
*)0xabcd1234;
47 char hw_serial
[HW_HOSTID_LEN
];
49 struct utsname utsname
= {
50 "userland", "libzpool", "1", "1", "na"
53 /* this only exists to have its address taken */
57 * =========================================================================
59 * =========================================================================
62 pthread_cond_t kthread_cond
= PTHREAD_COND_INITIALIZER
;
63 pthread_mutex_t kthread_lock
= PTHREAD_MUTEX_INITIALIZER
;
64 pthread_key_t kthread_key
;
72 VERIFY3S(pthread_key_create(&kthread_key
, NULL
), ==, 0);
74 /* Create entry for primary kthread */
75 kt
= umem_zalloc(sizeof(kthread_t
), UMEM_NOFAIL
);
76 kt
->t_tid
= pthread_self();
79 VERIFY3S(pthread_setspecific(kthread_key
, kt
), ==, 0);
81 /* Only the main thread should be running at the moment */
82 ASSERT3S(kthread_nr
, ==, 0);
89 kthread_t
*kt
= curthread
;
91 ASSERT(pthread_equal(kt
->t_tid
, pthread_self()));
92 ASSERT3P(kt
->t_func
, ==, NULL
);
94 umem_free(kt
, sizeof(kthread_t
));
96 /* Wait for all threads to exit via thread_exit() */
97 VERIFY3S(pthread_mutex_lock(&kthread_lock
), ==, 0);
99 kthread_nr
--; /* Main thread is exiting */
101 while (kthread_nr
> 0)
102 VERIFY3S(pthread_cond_wait(&kthread_cond
, &kthread_lock
), ==,
105 ASSERT3S(kthread_nr
, ==, 0);
106 VERIFY3S(pthread_mutex_unlock(&kthread_lock
), ==, 0);
108 VERIFY3S(pthread_key_delete(kthread_key
), ==, 0);
112 zk_thread_current(void)
114 kthread_t
*kt
= pthread_getspecific(kthread_key
);
116 ASSERT3P(kt
, !=, NULL
);
122 zk_thread_helper(void *arg
)
124 kthread_t
*kt
= (kthread_t
*) arg
;
126 VERIFY3S(pthread_setspecific(kthread_key
, kt
), ==, 0);
128 VERIFY3S(pthread_mutex_lock(&kthread_lock
), ==, 0);
130 VERIFY3S(pthread_mutex_unlock(&kthread_lock
), ==, 0);
132 kt
->t_tid
= pthread_self();
133 ((thread_func_arg_t
) kt
->t_func
)(kt
->t_arg
);
135 /* Unreachable, thread must exit with thread_exit() */
142 zk_thread_create(caddr_t stk
, size_t stksize
, thread_func_t func
, void *arg
,
143 size_t len
, proc_t
*pp
, int state
, pri_t pri
)
149 ASSERT3S(state
& ~TS_RUN
, ==, 0);
151 kt
= umem_zalloc(sizeof(kthread_t
), UMEM_NOFAIL
);
156 * The Solaris kernel stack size is 24k for x86/x86_64.
157 * The Linux kernel stack size is 8k for x86/x86_64.
159 * We reduce the default stack size in userspace, to ensure
160 * we observe stack overruns in user space as well as in
161 * kernel space. PTHREAD_STACK_MIN is the minimum stack
162 * required for a NULL procedure in user space and is added
163 * in to the stack requirements.
165 * Some buggy NPTL threading implementations include the
166 * guard area within the stack size allocations. In
167 * this case we allocate an extra page to account for the
168 * guard area since we only have two pages of usable stack
172 stack
= PTHREAD_STACK_MIN
+ MAX(stksize
, STACK_SIZE
) +
175 VERIFY3S(pthread_attr_init(&attr
), ==, 0);
176 VERIFY3S(pthread_attr_setstacksize(&attr
, stack
), ==, 0);
177 VERIFY3S(pthread_attr_setguardsize(&attr
, PAGESIZE
), ==, 0);
179 VERIFY3S(pthread_create(&kt
->t_tid
, &attr
, &zk_thread_helper
, kt
),
182 VERIFY3S(pthread_attr_destroy(&attr
), ==, 0);
190 kthread_t
*kt
= curthread
;
192 ASSERT(pthread_equal(kt
->t_tid
, pthread_self()));
194 umem_free(kt
, sizeof(kthread_t
));
196 pthread_mutex_lock(&kthread_lock
);
198 pthread_mutex_unlock(&kthread_lock
);
200 pthread_cond_broadcast(&kthread_cond
);
201 pthread_exit((void *)TS_MAGIC
);
205 zk_thread_join(kt_did_t tid
)
209 pthread_join((pthread_t
)tid
, &ret
);
210 VERIFY3P(ret
, ==, (void *)TS_MAGIC
);
214 * =========================================================================
216 * =========================================================================
220 kstat_create(char *module
, int instance
, char *name
, char *class,
221 uchar_t type
, ulong_t ndata
, uchar_t ks_flag
)
228 kstat_install(kstat_t
*ksp
)
233 kstat_delete(kstat_t
*ksp
)
237 * =========================================================================
239 * =========================================================================
243 mutex_init(kmutex_t
*mp
, char *name
, int type
, void *cookie
)
245 ASSERT3S(type
, ==, MUTEX_DEFAULT
);
246 ASSERT3P(cookie
, ==, NULL
);
247 mp
->m_owner
= MTX_INIT
;
248 mp
->m_magic
= MTX_MAGIC
;
249 VERIFY3S(pthread_mutex_init(&mp
->m_lock
, NULL
), ==, 0);
253 mutex_destroy(kmutex_t
*mp
)
255 ASSERT3U(mp
->m_magic
, ==, MTX_MAGIC
);
256 ASSERT3P(mp
->m_owner
, ==, MTX_INIT
);
257 VERIFY3S(pthread_mutex_destroy(&(mp
)->m_lock
), ==, 0);
258 mp
->m_owner
= MTX_DEST
;
263 mutex_enter(kmutex_t
*mp
)
265 ASSERT3U(mp
->m_magic
, ==, MTX_MAGIC
);
266 ASSERT3P(mp
->m_owner
, !=, MTX_DEST
);
267 ASSERT3P(mp
->m_owner
, !=, curthread
);
268 VERIFY3S(pthread_mutex_lock(&mp
->m_lock
), ==, 0);
269 ASSERT3P(mp
->m_owner
, ==, MTX_INIT
);
270 mp
->m_owner
= curthread
;
274 mutex_tryenter(kmutex_t
*mp
)
276 ASSERT3U(mp
->m_magic
, ==, MTX_MAGIC
);
277 ASSERT3P(mp
->m_owner
, !=, MTX_DEST
);
278 if (0 == pthread_mutex_trylock(&mp
->m_lock
)) {
279 ASSERT3P(mp
->m_owner
, ==, MTX_INIT
);
280 mp
->m_owner
= curthread
;
288 mutex_exit(kmutex_t
*mp
)
290 ASSERT3U(mp
->m_magic
, ==, MTX_MAGIC
);
291 ASSERT3P(mutex_owner(mp
), ==, curthread
);
292 mp
->m_owner
= MTX_INIT
;
293 VERIFY3S(pthread_mutex_unlock(&mp
->m_lock
), ==, 0);
297 mutex_owner(kmutex_t
*mp
)
299 ASSERT3U(mp
->m_magic
, ==, MTX_MAGIC
);
300 return (mp
->m_owner
);
304 mutex_held(kmutex_t
*mp
)
306 return (mp
->m_owner
== curthread
);
310 * =========================================================================
312 * =========================================================================
316 rw_init(krwlock_t
*rwlp
, char *name
, int type
, void *arg
)
318 ASSERT3S(type
, ==, RW_DEFAULT
);
319 ASSERT3P(arg
, ==, NULL
);
320 VERIFY3S(pthread_rwlock_init(&rwlp
->rw_lock
, NULL
), ==, 0);
321 rwlp
->rw_owner
= RW_INIT
;
322 rwlp
->rw_wr_owner
= RW_INIT
;
323 rwlp
->rw_readers
= 0;
324 rwlp
->rw_magic
= RW_MAGIC
;
328 rw_destroy(krwlock_t
*rwlp
)
330 ASSERT3U(rwlp
->rw_magic
, ==, RW_MAGIC
);
332 VERIFY3S(pthread_rwlock_destroy(&rwlp
->rw_lock
), ==, 0);
337 rw_enter(krwlock_t
*rwlp
, krw_t rw
)
339 ASSERT3U(rwlp
->rw_magic
, ==, RW_MAGIC
);
340 ASSERT3P(rwlp
->rw_owner
, !=, curthread
);
341 ASSERT3P(rwlp
->rw_wr_owner
, !=, curthread
);
343 if (rw
== RW_READER
) {
344 VERIFY3S(pthread_rwlock_rdlock(&rwlp
->rw_lock
), ==, 0);
345 ASSERT3P(rwlp
->rw_wr_owner
, ==, RW_INIT
);
347 atomic_inc_uint(&rwlp
->rw_readers
);
349 VERIFY3S(pthread_rwlock_wrlock(&rwlp
->rw_lock
), ==, 0);
350 ASSERT3P(rwlp
->rw_wr_owner
, ==, RW_INIT
);
351 ASSERT3U(rwlp
->rw_readers
, ==, 0);
353 rwlp
->rw_wr_owner
= curthread
;
356 rwlp
->rw_owner
= curthread
;
360 rw_exit(krwlock_t
*rwlp
)
362 ASSERT3U(rwlp
->rw_magic
, ==, RW_MAGIC
);
363 ASSERT(RW_LOCK_HELD(rwlp
));
365 if (RW_READ_HELD(rwlp
))
366 atomic_dec_uint(&rwlp
->rw_readers
);
368 rwlp
->rw_wr_owner
= RW_INIT
;
370 rwlp
->rw_owner
= RW_INIT
;
371 VERIFY3S(pthread_rwlock_unlock(&rwlp
->rw_lock
), ==, 0);
375 rw_tryenter(krwlock_t
*rwlp
, krw_t rw
)
379 ASSERT3U(rwlp
->rw_magic
, ==, RW_MAGIC
);
382 rv
= pthread_rwlock_tryrdlock(&rwlp
->rw_lock
);
384 rv
= pthread_rwlock_trywrlock(&rwlp
->rw_lock
);
387 ASSERT3P(rwlp
->rw_wr_owner
, ==, RW_INIT
);
390 atomic_inc_uint(&rwlp
->rw_readers
);
392 ASSERT3U(rwlp
->rw_readers
, ==, 0);
393 rwlp
->rw_wr_owner
= curthread
;
396 rwlp
->rw_owner
= curthread
;
400 VERIFY3S(rv
, ==, EBUSY
);
406 rw_tryupgrade(krwlock_t
*rwlp
)
408 ASSERT3U(rwlp
->rw_magic
, ==, RW_MAGIC
);
414 * =========================================================================
415 * condition variables
416 * =========================================================================
420 cv_init(kcondvar_t
*cv
, char *name
, int type
, void *arg
)
422 ASSERT3S(type
, ==, CV_DEFAULT
);
423 cv
->cv_magic
= CV_MAGIC
;
424 VERIFY3S(pthread_cond_init(&cv
->cv
, NULL
), ==, 0);
428 cv_destroy(kcondvar_t
*cv
)
430 ASSERT3U(cv
->cv_magic
, ==, CV_MAGIC
);
431 VERIFY3S(pthread_cond_destroy(&cv
->cv
), ==, 0);
436 cv_wait(kcondvar_t
*cv
, kmutex_t
*mp
)
438 ASSERT3U(cv
->cv_magic
, ==, CV_MAGIC
);
439 ASSERT3P(mutex_owner(mp
), ==, curthread
);
440 mp
->m_owner
= MTX_INIT
;
441 int ret
= pthread_cond_wait(&cv
->cv
, &mp
->m_lock
);
443 VERIFY3S(ret
, ==, EINTR
);
444 mp
->m_owner
= curthread
;
448 cv_timedwait(kcondvar_t
*cv
, kmutex_t
*mp
, clock_t abstime
)
455 ASSERT3U(cv
->cv_magic
, ==, CV_MAGIC
);
458 delta
= abstime
- ddi_get_lbolt();
462 VERIFY(gettimeofday(&tv
, NULL
) == 0);
464 ts
.tv_sec
= tv
.tv_sec
+ delta
/ hz
;
465 ts
.tv_nsec
= tv
.tv_usec
* 1000 + (delta
% hz
) * (NANOSEC
/ hz
);
466 if (ts
.tv_nsec
>= NANOSEC
) {
468 ts
.tv_nsec
-= NANOSEC
;
471 ASSERT3P(mutex_owner(mp
), ==, curthread
);
472 mp
->m_owner
= MTX_INIT
;
473 error
= pthread_cond_timedwait(&cv
->cv
, &mp
->m_lock
, &ts
);
474 mp
->m_owner
= curthread
;
476 if (error
== ETIMEDOUT
)
482 VERIFY3S(error
, ==, 0);
488 cv_signal(kcondvar_t
*cv
)
490 ASSERT3U(cv
->cv_magic
, ==, CV_MAGIC
);
491 VERIFY3S(pthread_cond_signal(&cv
->cv
), ==, 0);
495 cv_broadcast(kcondvar_t
*cv
)
497 ASSERT3U(cv
->cv_magic
, ==, CV_MAGIC
);
498 VERIFY3S(pthread_cond_broadcast(&cv
->cv
), ==, 0);
502 * =========================================================================
504 * =========================================================================
507 * Note: for the xxxat() versions of these functions, we assume that the
508 * starting vp is always rootdir (which is true for spa_directory.c, the only
509 * ZFS consumer of these interfaces). We assert this is true, and then emulate
510 * them by adding '/' in front of the path.
515 vn_open(char *path
, int x1
, int flags
, int mode
, vnode_t
**vpp
, int x2
, int x3
)
524 realpath
= umem_alloc(MAXPATHLEN
, UMEM_NOFAIL
);
527 * If we're accessing a real disk from userland, we need to use
528 * the character interface to avoid caching. This is particularly
529 * important if we're trying to look at a real in-kernel storage
530 * pool from userland, e.g. via zdb, because otherwise we won't
531 * see the changes occurring under the segmap cache.
532 * On the other hand, the stupid character device returns zero
533 * for its size. So -- gag -- we open the block device to get
534 * its size, and remember it for subsequent VOP_GETATTR().
536 if (strncmp(path
, "/dev/", 5) == 0) {
538 fd
= open64(path
, O_RDONLY
);
544 if (fstat64(fd
, &st
) == -1) {
551 (void) sprintf(realpath
, "%s", path
);
552 dsk
= strstr(path
, "/dsk/");
554 (void) sprintf(realpath
+ (dsk
- path
) + 1, "r%s",
557 (void) sprintf(realpath
, "%s", path
);
558 if (!(flags
& FCREAT
) && stat64(realpath
, &st
) == -1) {
566 old_umask
= umask(0);
569 * The construct 'flags - FREAD' conveniently maps combinations of
570 * FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
572 fd
= open64(realpath
, flags
- FREAD
, mode
);
576 (void) umask(old_umask
);
581 if (fstat64(fd
, &st
) == -1) {
587 (void) fcntl(fd
, F_SETFD
, FD_CLOEXEC
);
589 *vpp
= vp
= umem_zalloc(sizeof (vnode_t
), UMEM_NOFAIL
);
592 vp
->v_size
= st
.st_size
;
593 vp
->v_path
= spa_strdup(path
);
600 vn_openat(char *path
, int x1
, int flags
, int mode
, vnode_t
**vpp
, int x2
,
601 int x3
, vnode_t
*startvp
, int fd
)
603 char *realpath
= umem_alloc(strlen(path
) + 2, UMEM_NOFAIL
);
606 ASSERT(startvp
== rootdir
);
607 (void) sprintf(realpath
, "/%s", path
);
609 /* fd ignored for now, need if want to simulate nbmand support */
610 ret
= vn_open(realpath
, x1
, flags
, mode
, vpp
, x2
, x3
);
612 umem_free(realpath
, strlen(path
) + 2);
619 vn_rdwr(int uio
, vnode_t
*vp
, void *addr
, ssize_t len
, offset_t offset
,
620 int x1
, int x2
, rlim64_t x3
, void *x4
, ssize_t
*residp
)
622 ssize_t rc
, done
= 0, split
;
624 if (uio
== UIO_READ
) {
625 rc
= pread64(vp
->v_fd
, addr
, len
, offset
);
628 * To simulate partial disk writes, we split writes into two
629 * system calls so that the process can be killed in between.
631 split
= (len
> 0 ? rand() % len
: 0);
632 rc
= pwrite64(vp
->v_fd
, addr
, split
, offset
);
635 rc
= pwrite64(vp
->v_fd
, (char *)addr
+ split
,
636 len
- split
, offset
+ split
);
646 *residp
= len
- done
;
647 else if (done
!= len
)
653 vn_close(vnode_t
*vp
)
656 spa_strfree(vp
->v_path
);
657 umem_free(vp
, sizeof (vnode_t
));
661 * At a minimum we need to update the size since vdev_reopen()
662 * will no longer call vn_openat().
665 fop_getattr(vnode_t
*vp
, vattr_t
*vap
)
669 if (fstat64(vp
->v_fd
, &st
) == -1) {
674 vap
->va_size
= st
.st_size
;
681 * =========================================================================
682 * Figure out which debugging statements to print
683 * =========================================================================
686 static char *dprintf_string
;
687 static int dprintf_print_all
;
690 dprintf_find_string(const char *string
)
692 char *tmp_str
= dprintf_string
;
693 int len
= strlen(string
);
696 * Find out if this is a string we want to print.
697 * String format: file1.c,function_name1,file2.c,file3.c
700 while (tmp_str
!= NULL
) {
701 if (strncmp(tmp_str
, string
, len
) == 0 &&
702 (tmp_str
[len
] == ',' || tmp_str
[len
] == '\0'))
704 tmp_str
= strchr(tmp_str
, ',');
706 tmp_str
++; /* Get rid of , */
712 dprintf_setup(int *argc
, char **argv
)
717 * Debugging can be specified two ways: by setting the
718 * environment variable ZFS_DEBUG, or by including a
719 * "debug=..." argument on the command line. The command
720 * line setting overrides the environment variable.
723 for (i
= 1; i
< *argc
; i
++) {
724 int len
= strlen("debug=");
725 /* First look for a command line argument */
726 if (strncmp("debug=", argv
[i
], len
) == 0) {
727 dprintf_string
= argv
[i
] + len
;
728 /* Remove from args */
729 for (j
= i
; j
< *argc
; j
++)
736 if (dprintf_string
== NULL
) {
737 /* Look for ZFS_DEBUG environment variable */
738 dprintf_string
= getenv("ZFS_DEBUG");
742 * Are we just turning on all debugging?
744 if (dprintf_find_string("on"))
745 dprintf_print_all
= 1;
749 * =========================================================================
751 * =========================================================================
754 __dprintf(const char *file
, const char *func
, int line
, const char *fmt
, ...)
760 * Get rid of annoying "../common/" prefix to filename.
762 newfile
= strrchr(file
, '/');
763 if (newfile
!= NULL
) {
764 newfile
= newfile
+ 1; /* Get rid of leading / */
769 if (dprintf_print_all
||
770 dprintf_find_string(newfile
) ||
771 dprintf_find_string(func
)) {
772 /* Print out just the function name if requested */
774 if (dprintf_find_string("pid"))
775 (void) printf("%d ", getpid());
776 if (dprintf_find_string("tid"))
777 (void) printf("%u ", (uint_t
) pthread_self());
778 if (dprintf_find_string("cpu"))
779 (void) printf("%u ", getcpuid());
780 if (dprintf_find_string("time"))
781 (void) printf("%llu ", gethrtime());
782 if (dprintf_find_string("long"))
783 (void) printf("%s, line %d: ", newfile
, line
);
784 (void) printf("%s: ", func
);
786 (void) vprintf(fmt
, adx
);
792 #endif /* ZFS_DEBUG */
795 * =========================================================================
796 * cmn_err() and panic()
797 * =========================================================================
799 static char ce_prefix
[CE_IGNORE
][10] = { "", "NOTICE: ", "WARNING: ", "" };
800 static char ce_suffix
[CE_IGNORE
][2] = { "", "\n", "\n", "" };
803 vpanic(const char *fmt
, va_list adx
)
805 (void) fprintf(stderr
, "error: ");
806 (void) vfprintf(stderr
, fmt
, adx
);
807 (void) fprintf(stderr
, "\n");
809 abort(); /* think of it as a "user-level crash dump" */
813 panic(const char *fmt
, ...)
823 vcmn_err(int ce
, const char *fmt
, va_list adx
)
827 if (ce
!= CE_NOTE
) { /* suppress noise in userland stress testing */
828 (void) fprintf(stderr
, "%s", ce_prefix
[ce
]);
829 (void) vfprintf(stderr
, fmt
, adx
);
830 (void) fprintf(stderr
, "%s", ce_suffix
[ce
]);
836 cmn_err(int ce
, const char *fmt
, ...)
841 vcmn_err(ce
, fmt
, adx
);
846 * =========================================================================
848 * =========================================================================
851 kobj_open_file(char *name
)
856 /* set vp as the _fd field of the file */
857 if (vn_openat(name
, UIO_SYSSPACE
, FREAD
, 0, &vp
, 0, 0, rootdir
,
859 return ((void *)-1UL);
861 file
= umem_zalloc(sizeof (struct _buf
), UMEM_NOFAIL
);
862 file
->_fd
= (intptr_t)vp
;
867 kobj_read_file(struct _buf
*file
, char *buf
, unsigned size
, unsigned off
)
871 vn_rdwr(UIO_READ
, (vnode_t
*)file
->_fd
, buf
, size
, (offset_t
)off
,
872 UIO_SYSSPACE
, 0, 0, 0, &resid
);
874 return (size
- resid
);
878 kobj_close_file(struct _buf
*file
)
880 vn_close((vnode_t
*)file
->_fd
);
881 umem_free(file
, sizeof (struct _buf
));
885 kobj_get_filesize(struct _buf
*file
, uint64_t *size
)
888 vnode_t
*vp
= (vnode_t
*)file
->_fd
;
890 if (fstat64(vp
->v_fd
, &st
) == -1) {
899 * =========================================================================
901 * =========================================================================
907 poll(0, 0, ticks
* (1000 / hz
));
911 * Find highest one bit set.
912 * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
913 * High order bit is 31 (or 63 in _LP64 kernel).
923 if (i
& 0xffffffff00000000ul
) {
927 if (i
& 0xffff0000) {
945 static int random_fd
= -1, urandom_fd
= -1;
948 random_get_bytes_common(uint8_t *ptr
, size_t len
, int fd
)
956 bytes
= read(fd
, ptr
, resid
);
957 ASSERT3S(bytes
, >=, 0);
966 random_get_bytes(uint8_t *ptr
, size_t len
)
968 return (random_get_bytes_common(ptr
, len
, random_fd
));
972 random_get_pseudo_bytes(uint8_t *ptr
, size_t len
)
974 return (random_get_bytes_common(ptr
, len
, urandom_fd
));
978 ddi_strtoul(const char *hw_serial
, char **nptr
, int base
, unsigned long *result
)
982 *result
= strtoul(hw_serial
, &end
, base
);
989 ddi_strtoull(const char *str
, char **nptr
, int base
, u_longlong_t
*result
)
993 *result
= strtoull(str
, &end
, base
);
1000 * =========================================================================
1001 * kernel emulation setup & teardown
1002 * =========================================================================
1005 umem_out_of_memory(void)
1007 char errmsg
[] = "out of memory -- generating core dump\n";
1009 (void) fprintf(stderr
, "%s", errmsg
);
1015 kernel_init(int mode
)
1017 umem_nofail_callback(umem_out_of_memory
);
1019 physmem
= sysconf(_SC_PHYS_PAGES
);
1021 dprintf("physmem = %llu pages (%.2f GB)\n", physmem
,
1022 (double)physmem
* sysconf(_SC_PAGE_SIZE
) / (1ULL << 30));
1024 (void) snprintf(hw_serial
, sizeof (hw_serial
), "%ld",
1025 (mode
& FWRITE
) ? gethostid() : 0);
1027 VERIFY((random_fd
= open("/dev/random", O_RDONLY
)) != -1);
1028 VERIFY((urandom_fd
= open("/dev/urandom", O_RDONLY
)) != -1);
1031 system_taskq_init();
1041 system_taskq_fini();
1052 crgetuid(cred_t
*cr
)
1058 crgetgid(cred_t
*cr
)
1064 crgetngroups(cred_t
*cr
)
1070 crgetgroups(cred_t
*cr
)
1076 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
1082 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
1088 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
1094 ksid_lookupdomain(const char *dom
)
1098 kd
= umem_zalloc(sizeof (ksiddomain_t
), UMEM_NOFAIL
);
1099 kd
->kd_name
= spa_strdup(dom
);
1104 ksiddomain_rele(ksiddomain_t
*ksid
)
1106 spa_strfree(ksid
->kd_name
);
1107 umem_free(ksid
, sizeof (ksiddomain_t
));
1111 kmem_vasprintf(const char *fmt
, va_list adx
)
1116 va_copy(adx_copy
, adx
);
1117 VERIFY(vasprintf(&buf
, fmt
, adx_copy
) != -1);
1124 kmem_asprintf(const char *fmt
, ...)
1130 VERIFY(vasprintf(&buf
, fmt
, adx
) != -1);
1138 zfs_onexit_fd_hold(int fd
, minor_t
*minorp
)
1146 zfs_onexit_fd_rele(int fd
)
1152 zfs_onexit_add_cb(minor_t minor
, void (*func
)(void *), void *data
,
1153 uint64_t *action_handle
)
1160 zfs_onexit_del_cb(minor_t minor
, uint64_t action_handle
, boolean_t fire
)
1167 zfs_onexit_cb_data(minor_t minor
, uint64_t action_handle
, void **data
)