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