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
)
520 char realpath
[MAXPATHLEN
];
525 * If we're accessing a real disk from userland, we need to use
526 * the character interface to avoid caching. This is particularly
527 * important if we're trying to look at a real in-kernel storage
528 * pool from userland, e.g. via zdb, because otherwise we won't
529 * see the changes occurring under the segmap cache.
530 * On the other hand, the stupid character device returns zero
531 * for its size. So -- gag -- we open the block device to get
532 * its size, and remember it for subsequent VOP_GETATTR().
534 if (strncmp(path
, "/dev/", 5) == 0) {
536 fd
= open64(path
, O_RDONLY
);
539 if (fstat64(fd
, &st
) == -1) {
544 (void) sprintf(realpath
, "%s", path
);
545 dsk
= strstr(path
, "/dsk/");
547 (void) sprintf(realpath
+ (dsk
- path
) + 1, "r%s",
550 (void) sprintf(realpath
, "%s", path
);
551 if (!(flags
& FCREAT
) && stat64(realpath
, &st
) == -1)
556 old_umask
= umask(0);
559 * The construct 'flags - FREAD' conveniently maps combinations of
560 * FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
562 fd
= open64(realpath
, flags
- FREAD
, mode
);
565 (void) umask(old_umask
);
570 if (fstat64(fd
, &st
) == -1) {
576 (void) fcntl(fd
, F_SETFD
, FD_CLOEXEC
);
578 *vpp
= vp
= umem_zalloc(sizeof (vnode_t
), UMEM_NOFAIL
);
581 vp
->v_size
= st
.st_size
;
582 vp
->v_path
= spa_strdup(path
);
589 vn_openat(char *path
, int x1
, int flags
, int mode
, vnode_t
**vpp
, int x2
,
590 int x3
, vnode_t
*startvp
, int fd
)
592 char *realpath
= umem_alloc(strlen(path
) + 2, UMEM_NOFAIL
);
595 ASSERT(startvp
== rootdir
);
596 (void) sprintf(realpath
, "/%s", path
);
598 /* fd ignored for now, need if want to simulate nbmand support */
599 ret
= vn_open(realpath
, x1
, flags
, mode
, vpp
, x2
, x3
);
601 umem_free(realpath
, strlen(path
) + 2);
608 vn_rdwr(int uio
, vnode_t
*vp
, void *addr
, ssize_t len
, offset_t offset
,
609 int x1
, int x2
, rlim64_t x3
, void *x4
, ssize_t
*residp
)
611 ssize_t rc
, done
= 0, split
;
613 if (uio
== UIO_READ
) {
614 rc
= pread64(vp
->v_fd
, addr
, len
, offset
);
617 * To simulate partial disk writes, we split writes into two
618 * system calls so that the process can be killed in between.
620 split
= (len
> 0 ? rand() % len
: 0);
621 rc
= pwrite64(vp
->v_fd
, addr
, split
, offset
);
624 rc
= pwrite64(vp
->v_fd
, (char *)addr
+ split
,
625 len
- split
, offset
+ split
);
635 *residp
= len
- done
;
636 else if (done
!= len
)
642 vn_close(vnode_t
*vp
)
645 spa_strfree(vp
->v_path
);
646 umem_free(vp
, sizeof (vnode_t
));
650 * At a minimum we need to update the size since vdev_reopen()
651 * will no longer call vn_openat().
654 fop_getattr(vnode_t
*vp
, vattr_t
*vap
)
658 if (fstat64(vp
->v_fd
, &st
) == -1) {
663 vap
->va_size
= st
.st_size
;
670 * =========================================================================
671 * Figure out which debugging statements to print
672 * =========================================================================
675 static char *dprintf_string
;
676 static int dprintf_print_all
;
679 dprintf_find_string(const char *string
)
681 char *tmp_str
= dprintf_string
;
682 int len
= strlen(string
);
685 * Find out if this is a string we want to print.
686 * String format: file1.c,function_name1,file2.c,file3.c
689 while (tmp_str
!= NULL
) {
690 if (strncmp(tmp_str
, string
, len
) == 0 &&
691 (tmp_str
[len
] == ',' || tmp_str
[len
] == '\0'))
693 tmp_str
= strchr(tmp_str
, ',');
695 tmp_str
++; /* Get rid of , */
701 dprintf_setup(int *argc
, char **argv
)
706 * Debugging can be specified two ways: by setting the
707 * environment variable ZFS_DEBUG, or by including a
708 * "debug=..." argument on the command line. The command
709 * line setting overrides the environment variable.
712 for (i
= 1; i
< *argc
; i
++) {
713 int len
= strlen("debug=");
714 /* First look for a command line argument */
715 if (strncmp("debug=", argv
[i
], len
) == 0) {
716 dprintf_string
= argv
[i
] + len
;
717 /* Remove from args */
718 for (j
= i
; j
< *argc
; j
++)
725 if (dprintf_string
== NULL
) {
726 /* Look for ZFS_DEBUG environment variable */
727 dprintf_string
= getenv("ZFS_DEBUG");
731 * Are we just turning on all debugging?
733 if (dprintf_find_string("on"))
734 dprintf_print_all
= 1;
738 * =========================================================================
740 * =========================================================================
743 __dprintf(const char *file
, const char *func
, int line
, const char *fmt
, ...)
749 * Get rid of annoying "../common/" prefix to filename.
751 newfile
= strrchr(file
, '/');
752 if (newfile
!= NULL
) {
753 newfile
= newfile
+ 1; /* Get rid of leading / */
758 if (dprintf_print_all
||
759 dprintf_find_string(newfile
) ||
760 dprintf_find_string(func
)) {
761 /* Print out just the function name if requested */
763 if (dprintf_find_string("pid"))
764 (void) printf("%d ", getpid());
765 if (dprintf_find_string("tid"))
766 (void) printf("%u ", (uint_t
) pthread_self());
767 if (dprintf_find_string("cpu"))
768 (void) printf("%u ", getcpuid());
769 if (dprintf_find_string("time"))
770 (void) printf("%llu ", gethrtime());
771 if (dprintf_find_string("long"))
772 (void) printf("%s, line %d: ", newfile
, line
);
773 (void) printf("%s: ", func
);
775 (void) vprintf(fmt
, adx
);
781 #endif /* ZFS_DEBUG */
784 * =========================================================================
785 * cmn_err() and panic()
786 * =========================================================================
788 static char ce_prefix
[CE_IGNORE
][10] = { "", "NOTICE: ", "WARNING: ", "" };
789 static char ce_suffix
[CE_IGNORE
][2] = { "", "\n", "\n", "" };
792 vpanic(const char *fmt
, va_list adx
)
794 (void) fprintf(stderr
, "error: ");
795 (void) vfprintf(stderr
, fmt
, adx
);
796 (void) fprintf(stderr
, "\n");
798 abort(); /* think of it as a "user-level crash dump" */
802 panic(const char *fmt
, ...)
812 vcmn_err(int ce
, const char *fmt
, va_list adx
)
816 if (ce
!= CE_NOTE
) { /* suppress noise in userland stress testing */
817 (void) fprintf(stderr
, "%s", ce_prefix
[ce
]);
818 (void) vfprintf(stderr
, fmt
, adx
);
819 (void) fprintf(stderr
, "%s", ce_suffix
[ce
]);
825 cmn_err(int ce
, const char *fmt
, ...)
830 vcmn_err(ce
, fmt
, adx
);
835 * =========================================================================
837 * =========================================================================
840 kobj_open_file(char *name
)
845 /* set vp as the _fd field of the file */
846 if (vn_openat(name
, UIO_SYSSPACE
, FREAD
, 0, &vp
, 0, 0, rootdir
,
848 return ((void *)-1UL);
850 file
= umem_zalloc(sizeof (struct _buf
), UMEM_NOFAIL
);
851 file
->_fd
= (intptr_t)vp
;
856 kobj_read_file(struct _buf
*file
, char *buf
, unsigned size
, unsigned off
)
860 vn_rdwr(UIO_READ
, (vnode_t
*)file
->_fd
, buf
, size
, (offset_t
)off
,
861 UIO_SYSSPACE
, 0, 0, 0, &resid
);
863 return (size
- resid
);
867 kobj_close_file(struct _buf
*file
)
869 vn_close((vnode_t
*)file
->_fd
);
870 umem_free(file
, sizeof (struct _buf
));
874 kobj_get_filesize(struct _buf
*file
, uint64_t *size
)
877 vnode_t
*vp
= (vnode_t
*)file
->_fd
;
879 if (fstat64(vp
->v_fd
, &st
) == -1) {
888 * =========================================================================
890 * =========================================================================
896 poll(0, 0, ticks
* (1000 / hz
));
900 * Find highest one bit set.
901 * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
902 * High order bit is 31 (or 63 in _LP64 kernel).
912 if (i
& 0xffffffff00000000ul
) {
916 if (i
& 0xffff0000) {
934 static int random_fd
= -1, urandom_fd
= -1;
937 random_get_bytes_common(uint8_t *ptr
, size_t len
, int fd
)
945 bytes
= read(fd
, ptr
, resid
);
946 ASSERT3S(bytes
, >=, 0);
955 random_get_bytes(uint8_t *ptr
, size_t len
)
957 return (random_get_bytes_common(ptr
, len
, random_fd
));
961 random_get_pseudo_bytes(uint8_t *ptr
, size_t len
)
963 return (random_get_bytes_common(ptr
, len
, urandom_fd
));
967 ddi_strtoul(const char *hw_serial
, char **nptr
, int base
, unsigned long *result
)
971 *result
= strtoul(hw_serial
, &end
, base
);
978 ddi_strtoull(const char *str
, char **nptr
, int base
, u_longlong_t
*result
)
982 *result
= strtoull(str
, &end
, base
);
989 * =========================================================================
990 * kernel emulation setup & teardown
991 * =========================================================================
994 umem_out_of_memory(void)
996 char errmsg
[] = "out of memory -- generating core dump\n";
998 (void) fprintf(stderr
, "%s", errmsg
);
1004 kernel_init(int mode
)
1006 umem_nofail_callback(umem_out_of_memory
);
1008 physmem
= sysconf(_SC_PHYS_PAGES
);
1010 dprintf("physmem = %llu pages (%.2f GB)\n", physmem
,
1011 (double)physmem
* sysconf(_SC_PAGE_SIZE
) / (1ULL << 30));
1013 (void) snprintf(hw_serial
, sizeof (hw_serial
), "%ld",
1014 (mode
& FWRITE
) ? gethostid() : 0);
1016 VERIFY((random_fd
= open("/dev/random", O_RDONLY
)) != -1);
1017 VERIFY((urandom_fd
= open("/dev/urandom", O_RDONLY
)) != -1);
1020 system_taskq_init();
1030 system_taskq_fini();
1041 crgetuid(cred_t
*cr
)
1047 crgetgid(cred_t
*cr
)
1053 crgetngroups(cred_t
*cr
)
1059 crgetgroups(cred_t
*cr
)
1065 zfs_secpolicy_snapshot_perms(const char *name
, cred_t
*cr
)
1071 zfs_secpolicy_rename_perms(const char *from
, const char *to
, cred_t
*cr
)
1077 zfs_secpolicy_destroy_perms(const char *name
, cred_t
*cr
)
1083 ksid_lookupdomain(const char *dom
)
1087 kd
= umem_zalloc(sizeof (ksiddomain_t
), UMEM_NOFAIL
);
1088 kd
->kd_name
= spa_strdup(dom
);
1093 ksiddomain_rele(ksiddomain_t
*ksid
)
1095 spa_strfree(ksid
->kd_name
);
1096 umem_free(ksid
, sizeof (ksiddomain_t
));
1100 * Do not change the length of the returned string; it must be freed
1104 kmem_asprintf(const char *fmt
, ...)
1111 size
= vsnprintf(NULL
, 0, fmt
, adx
) + 1;
1114 buf
= kmem_alloc(size
, KM_SLEEP
);
1117 size
= vsnprintf(buf
, size
, fmt
, adx
);
1125 zfs_onexit_fd_hold(int fd
, minor_t
*minorp
)
1133 zfs_onexit_fd_rele(int fd
)
1139 zfs_onexit_add_cb(minor_t minor
, void (*func
)(void *), void *data
,
1140 uint64_t *action_handle
)
1147 zfs_onexit_del_cb(minor_t minor
, uint64_t action_handle
, boolean_t fire
)
1154 zfs_onexit_cb_data(minor_t minor
, uint64_t action_handle
, void **data
)