1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21fa9e406ahrens/*
22c99e4bdChris Kirby * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
239a686fbPaul Dagnelie * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24b3d32f0Bryan Cantrill * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
25f06dce2Andrew Stormont * Copyright 2017 RackTop Systems.
26fa9e406ahrens */
27fa9e406ahrens
28fa9e406ahrens#include <assert.h>
29c9431faahl#include <fcntl.h>
30fa9e406ahrens#include <poll.h>
31fa9e406ahrens#include <stdio.h>
32fa9e406ahrens#include <stdlib.h>
33c9431faahl#include <string.h>
34c9431faahl#include <zlib.h>
35df15e41Matthew Ahrens#include <libgen.h>
36fa9e406ahrens#include <sys/spa.h>
37c9431faahl#include <sys/stat.h>
38fa9e406ahrens#include <sys/processor.h>
39c9431faahl#include <sys/zfs_context.h>
403b2aab1Matthew Ahrens#include <sys/rrwlock.h>
41c9431faahl#include <sys/zmod.h>
429517395ek#include <sys/utsname.h>
435679c89jv#include <sys/systeminfo.h>
44e0f1c0aOlaf Faaland#include <libzfs.h>
45eb63303Tom Caputi#include <sys/crypto/common.h>
46eb63303Tom Caputi#include <sys/crypto/impl.h>
47eb63303Tom Caputi#include <sys/crypto/api.h>
48eb63303Tom Caputi#include <sys/sha2.h>
49eb63303Tom Caputi#include <crypto/aes/aes_impl.h>
505ad8204nd
51f06dce2Andrew Stormontextern void system_taskq_init(void);
52f06dce2Andrew Stormontextern void system_taskq_fini(void);
53f06dce2Andrew Stormont
54fa9e406ahrens/*
55fa9e406ahrens * Emulation of kernel services in userland.
56fa9e406ahrens */
57fa9e406ahrens
58f06dce2Andrew Stormontpgcnt_t physmem;
59fa9e406ahrensvnode_t *rootdir = (vnode_t *)0xabcd1234;
605679c89jvchar hw_serial[HW_HOSTID_LEN];
61283b846George.Wilsonkmutex_t cpu_lock;
6294dd93aGeorge Wilsonvmem_t *zio_arena = NULL;
639517395ek
64df15e41Matthew Ahrens/* If set, all blocks read will be copied to the specified directory. */
65df15e41Matthew Ahrenschar *vn_dumpdir = NULL;
66df15e41Matthew Ahrens
679517395ekstruct utsname utsname = {
689517395ek	"userland", "libzpool", "1", "1", "na"
699517395ek};
70fa9e406ahrens
71fa9e406ahrens/*
72fa9e406ahrens * =========================================================================
73fa9e406ahrens * vnode operations
74fa9e406ahrens * =========================================================================
75fa9e406ahrens */
76fa9e406ahrens/*
77fa9e406ahrens * Note: for the xxxat() versions of these functions, we assume that the
78fa9e406ahrens * starting vp is always rootdir (which is true for spa_directory.c, the only
79fa9e406ahrens * ZFS consumer of these interfaces).  We assert this is true, and then emulate
80fa9e406ahrens * them by adding '/' in front of the path.
81fa9e406ahrens */
82fa9e406ahrens
83fa9e406ahrens/*ARGSUSED*/
84fa9e406ahrensint
85fa9e406ahrensvn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
86fa9e406ahrens{
87fa9e406ahrens	int fd;
88df15e41Matthew Ahrens	int dump_fd;
89fa9e406ahrens	vnode_t *vp;
90fa9e406ahrens	int old_umask;
91fa9e406ahrens	char realpath[MAXPATHLEN];
92fa9e406ahrens	struct stat64 st;
93fa9e406ahrens
94fa9e406ahrens	/*
95fa9e406ahrens	 * If we're accessing a real disk from userland, we need to use
96fa9e406ahrens	 * the character interface to avoid caching.  This is particularly
97fa9e406ahrens	 * important if we're trying to look at a real in-kernel storage
98fa9e406ahrens	 * pool from userland, e.g. via zdb, because otherwise we won't
99fa9e406ahrens	 * see the changes occurring under the segmap cache.
100fa9e406ahrens	 * On the other hand, the stupid character device returns zero
101fa9e406ahrens	 * for its size.  So -- gag -- we open the block device to get
102fa9e406ahrens	 * its size, and remember it for subsequent VOP_GETATTR().
103fa9e406ahrens	 */
104fa9e406ahrens	if (strncmp(path, "/dev/", 5) == 0) {
105fa9e406ahrens		char *dsk;
106fa9e406ahrens		fd = open64(path, O_RDONLY);
107fa9e406ahrens		if (fd == -1)
108fa9e406ahrens			return (errno);
109fa9e406ahrens		if (fstat64(fd, &st) == -1) {
110fa9e406ahrens			close(fd);
111fa9e406ahrens			return (errno);
112fa9e406ahrens		}
113fa9e406ahrens		close(fd);
114fa9e406ahrens		(void) sprintf(realpath, "%s", path);
115fa9e406ahrens		dsk = strstr(path, "/dsk/");
116fa9e406ahrens		if (dsk != NULL)
117fa9e406ahrens			(void) sprintf(realpath + (dsk - path) + 1, "r%s",
118fa9e406ahrens			    dsk + 1);
119fa9e406ahrens	} else {
120fa9e406ahrens		(void) sprintf(realpath, "%s", path);
121fa9e406ahrens		if (!(flags & FCREAT) && stat64(realpath, &st) == -1)
122fa9e406ahrens			return (errno);
123fa9e406ahrens	}
124fa9e406ahrens
125fa9e406ahrens	if (flags & FCREAT)
126fa9e406ahrens		old_umask = umask(0);
127fa9e406ahrens
128fa9e406ahrens	/*
129fa9e406ahrens	 * The construct 'flags - FREAD' conveniently maps combinations of
130fa9e406ahrens	 * FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
131fa9e406ahrens	 */
132fa9e406ahrens	fd = open64(realpath, flags - FREAD, mode);
133fa9e406ahrens
134fa9e406ahrens	if (flags & FCREAT)
135fa9e406ahrens		(void) umask(old_umask);
136fa9e406ahrens
137df15e41Matthew Ahrens	if (vn_dumpdir != NULL) {
138df15e41Matthew Ahrens		char dumppath[MAXPATHLEN];
139df15e41Matthew Ahrens		(void) snprintf(dumppath, sizeof (dumppath),
140df15e41Matthew Ahrens		    "%s/%s", vn_dumpdir, basename(realpath));
141df15e41Matthew Ahrens		dump_fd = open64(dumppath, O_CREAT | O_WRONLY, 0666);
142df15e41Matthew Ahrens		if (dump_fd == -1)
143df15e41Matthew Ahrens			return (errno);
144df15e41Matthew Ahrens	} else {
145df15e41Matthew Ahrens		dump_fd = -1;
146df15e41Matthew Ahrens	}
147df15e41Matthew Ahrens
148fa9e406ahrens	if (fd == -1)
149fa9e406ahrens		return (errno);
150fa9e406ahrens
151fa9e406ahrens	if (fstat64(fd, &st) == -1) {
152fa9e406ahrens		close(fd);
153fa9e406ahrens		return (errno);
154fa9e406ahrens	}
155fa9e406ahrens
156fa9e406ahrens	(void) fcntl(fd, F_SETFD, FD_CLOEXEC);
157fa9e406ahrens
158fa9e406ahrens	*vpp = vp = umem_zalloc(sizeof (vnode_t), UMEM_NOFAIL);
159fa9e406ahrens
160fa9e406ahrens	vp->v_fd = fd;
161fa9e406ahrens	vp->v_size = st.st_size;
162fa9e406ahrens	vp->v_path = spa_strdup(path);
163df15e41Matthew Ahrens	vp->v_dump_fd = dump_fd;
164fa9e406ahrens
165fa9e406ahrens	return (0);
166fa9e406ahrens}
167fa9e406ahrens
168da6c28aamw/*ARGSUSED*/
169fa9e406ahrensint
170fa9e406ahrensvn_openat(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2,
171da6c28aamw    int x3, vnode_t *startvp, int fd)
172fa9e406ahrens{
173fa9e406ahrens	char *realpath = umem_alloc(strlen(path) + 2, UMEM_NOFAIL);
174fa9e406ahrens	int ret;
175fa9e406ahrens
176fa9e406ahrens	ASSERT(startvp == rootdir);
177fa9e406ahrens	(void) sprintf(realpath, "/%s", path);
178fa9e406ahrens
179da6c28aamw	/* fd ignored for now, need if want to simulate nbmand support */
180fa9e406ahrens	ret = vn_open(realpath, x1, flags, mode, vpp, x2, x3);
181fa9e406ahrens
182fa9e406ahrens	umem_free(realpath, strlen(path) + 2);
183fa9e406ahrens
184fa9e406ahrens	return (ret);
185fa9e406ahrens}
186fa9e406ahrens
187fa9e406ahrens/*ARGSUSED*/
188fa9e406ahrensint
189fa9e406ahrensvn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset,
1909a686fbPaul Dagnelie    int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp)
191fa9e406ahrens{
192fa9e406ahrens	ssize_t iolen, split;
193fa9e406ahrens
194fa9e406ahrens	if (uio == UIO_READ) {
195fa9e406ahrens		iolen = pread64(vp->v_fd, addr, len, offset);
196df15e41Matthew Ahrens		if (vp->v_dump_fd != -1) {
197df15e41Matthew Ahrens			int status =
198df15e41Matthew Ahrens			    pwrite64(vp->v_dump_fd, addr, iolen, offset);
199df15e41Matthew Ahrens			ASSERT(status != -1);
200df15e41Matthew Ahrens		}
201fa9e406ahrens	} else {
202fa9e406ahrens		/*
203fa9e406ahrens		 * To simulate partial disk writes, we split writes into two
204fa9e406ahrens		 * system calls so that the process can be killed in between.
205fa9e406ahrens		 */
206ad135b5Christopher Siden		int sectors = len >> SPA_MINBLOCKSHIFT;
207ad135b5Christopher Siden		split = (sectors > 0 ? rand() % sectors : 0) <<
208ad135b5Christopher Siden		    SPA_MINBLOCKSHIFT;
209fa9e406ahrens		iolen = pwrite64(vp->v_fd, addr, split, offset);
210fa9e406ahrens		iolen += pwrite64(vp->v_fd, (char *)addr + split,
211fa9e406ahrens		    len - split, offset + split);
212fa9e406ahrens	}
213fa9e406ahrens
214fa9e406ahrens	if (iolen == -1)
215fa9e406ahrens		return (errno);
216fa9e406ahrens	if (residp)
217fa9e406ahrens		*residp = len - iolen;
218fa9e406ahrens	else if (iolen != len)
219fa9e406ahrens		return (EIO);
220fa9e406ahrens	return (0);
221fa9e406ahrens}
222fa9e406ahrens
223fa9e406ahrensvoid
224fa9e406ahrensvn_close(vnode_t *vp)
225fa9e406ahrens{
226fa9e406ahrens	close(vp->v_fd);
227df15e41Matthew Ahrens	if (vp->v_dump_fd != -1)
228df15e41Matthew Ahrens		close(vp->v_dump_fd);
229fa9e406ahrens	spa_strfree(vp->v_path);
230fa9e406ahrens	umem_free(vp, sizeof (vnode_t));
231fa9e406ahrens}
232fa9e406ahrens
233095bcd6George Wilson/*
234095bcd6George Wilson * At a minimum we need to update the size since vdev_reopen()
235095bcd6George Wilson * will no longer call vn_openat().
236095bcd6George Wilson */
237095bcd6George Wilsonint
238095bcd6George Wilsonfop_getattr(vnode_t *vp, vattr_t *vap)
239095bcd6George Wilson{
240095bcd6George Wilson	struct stat64 st;
241095bcd6George Wilson
242095bcd6George Wilson	if (fstat64(vp->v_fd, &st) == -1) {
243095bcd6George Wilson		close(vp->v_fd);
244095bcd6George Wilson		return (errno);
245095bcd6George Wilson	}
246095bcd6George Wilson
247095bcd6George Wilson	vap->va_size = st.st_size;
248095bcd6George Wilson	return (0);
249095bcd6George Wilson}
250095bcd6George Wilson
251fa9e406ahrens#ifdef ZFS_DEBUG
252fa9e406ahrens
253fa9e406ahrens/*
254fa9e406ahrens * =========================================================================
255fa9e406ahrens * Figure out which debugging statements to print
256fa9e406ahrens * =========================================================================
257fa9e406ahrens */
258fa9e406ahrens
259fa9e406ahrensstatic char *dprintf_string;
260fa9e406ahrensstatic int dprintf_print_all;
261fa9e406ahrens
262fa9e406ahrensint
263fa9e406ahrensdprintf_find_string(const char *string)
264fa9e406ahrens{
265fa9e406ahrens	char *tmp_str = dprintf_string;
266fa9e406ahrens	int len = strlen(string);
267fa9e406ahrens
268fa9e406ahrens	/*
269fa9e406ahrens	 * Find out if this is a string we want to print.
270fa9e406ahrens	 * String format: file1.c,function_name1,file2.c,file3.c
271fa9e406ahrens	 */
272fa9e406ahrens
273fa9e406ahrens	while (tmp_str != NULL) {
274fa9e406ahrens		if (strncmp(tmp_str, string, len) == 0 &&
275fa9e406ahrens		    (tmp_str[len] == ',' || tmp_str[len] == '\0'))
276fa9e406ahrens			return (1);
277fa9e406ahrens		tmp_str = strchr(tmp_str, ',');
278fa9e406ahrens		if (tmp_str != NULL)
279fa9e406ahrens			tmp_str++; /* Get rid of , */
280fa9e406ahrens	}
281fa9e406ahrens	return (0);
282fa9e406ahrens}
283fa9e406ahrens
284fa9e406ahrensvoid
285fa9e406ahrensdprintf_setup(int *argc, char **argv)
286fa9e406ahrens{
287fa9e406ahrens	int i, j;
288fa9e406ahrens
289fa9e406ahrens	/*
290fa9e406ahrens	 * Debugging can be specified two ways: by setting the
291fa9e406ahrens	 * environment variable ZFS_DEBUG, or by including a
292fa9e406ahrens	 * "debug=..."  argument on the command line.  The command
293fa9e406ahrens	 * line setting overrides the environment variable.
294fa9e406ahrens	 */
295fa9e406ahrens
296fa9e406ahrens	for (i = 1; i < *argc; i++) {
297fa9e406ahrens		int len = strlen("debug=");
298fa9e406ahrens		/* First look for a command line argument */
299fa9e406ahrens		if (strncmp("debug=", argv[i], len) == 0) {
300fa9e406ahrens			dprintf_string = argv[i] + len;
301fa9e406ahrens			/* Remove from args */
302fa9e406ahrens			for (j = i; j < *argc; j++)
303fa9e406ahrens				argv[j] = argv[j+1];
304fa9e406ahrens			argv[j] = NULL;
305fa9e406ahrens			(*argc)--;
306fa9e406ahrens		}
307fa9e406ahrens	}
308fa9e406ahrens
309fa9e406ahrens	if (dprintf_string == NULL) {
310fa9e406ahrens		/* Look for ZFS_DEBUG environment variable */
311fa9e406ahrens		dprintf_string = getenv("ZFS_DEBUG");
312fa9e406ahrens	}
313fa9e406ahrens
314fa9e406ahrens	/*
315fa9e406ahrens	 * Are we just turning on all debugging?
316fa9e406ahrens	 */
317fa9e406ahrens	if (dprintf_find_string("on"))
318fa9e406ahrens		dprintf_print_all = 1;
3197fa49eaMatthew Ahrens
3207fa49eaMatthew Ahrens	if (dprintf_string != NULL)
3217fa49eaMatthew Ahrens		zfs_flags |= ZFS_DEBUG_DPRINTF;
322fa9e406ahrens}
323fa9e406ahrens
324fa9e406ahrens/*
325fa9e406ahrens * =========================================================================
326fa9e406ahrens * debug printfs
327fa9e406ahrens * =========================================================================
328fa9e406ahrens */
329fa9e406ahrensvoid
330fa9e406ahrens__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
331fa9e406ahrens{
332fa9e406ahrens	const char *newfile;
333fa9e406ahrens	va_list adx;
334fa9e406ahrens
335fa9e406ahrens	/*
336fa9e406ahrens	 * Get rid of annoying "../common/" prefix to filename.
337fa9e406ahrens	 */
338fa9e406ahrens	newfile = strrchr(file, '/');
339fa9e406ahrens	if (newfile != NULL) {
340fa9e406ahrens		newfile = newfile + 1; /* Get rid of leading / */
341fa9e406ahrens	} else {
342fa9e406ahrens		newfile = file;
343fa9e406ahrens	}
344fa9e406ahrens
345fa9e406ahrens	if (dprintf_print_all ||
346fa9e406ahrens	    dprintf_find_string(newfile) ||
347fa9e406ahrens	    dprintf_find_string(func)) {
348fa9e406ahrens		/* Print out just the function name if requested */
349fa9e406ahrens		flockfile(stdout);
350fa9e406ahrens		if (dprintf_find_string("pid"))
351fa9e406ahrens			(void) printf("%d ", getpid());
352fa9e406ahrens		if (dprintf_find_string("tid"))
353fa9e406ahrens			(void) printf("%u ", thr_self());
354fa9e406ahrens		if (dprintf_find_string("cpu"))
355fa9e406ahrens			(void) printf("%u ", getcpuid());
356fa9e406ahrens		if (dprintf_find_string("time"))
357fa9e406ahrens			(void) printf("%llu ", gethrtime());
358fa9e406ahrens		if (dprintf_find_string("long"))
359fa9e406ahrens			(void) printf("%s, line %d: ", newfile, line);
360fa9e406ahrens		(void) printf("%s: ", func);
361fa9e406ahrens		va_start(adx, fmt);
362fa9e406ahrens		(void) vprintf(fmt, adx);
363fa9e406ahrens		va_end(adx);
364fa9e406ahrens		funlockfile(stdout);
365fa9e406ahrens	}
366fa9e406ahrens}
367fa9e406ahrens
368fa9e406ahrens#endif /* ZFS_DEBUG */
369fa9e406ahrens
370fa9e406ahrens/*
371fa9e406ahrens * =========================================================================
372ea8dc4beschrock * kobj interfaces
373ea8dc4beschrock * =========================================================================
374ea8dc4beschrock */
375ea8dc4beschrockstruct _buf *
376ea8dc4beschrockkobj_open_file(char *name)
377ea8dc4beschrock{
378ea8dc4beschrock	struct _buf *file;
379ea8dc4beschrock	vnode_t *vp;
380ea8dc4beschrock
381ea8dc4beschrock	/* set vp as the _fd field of the file */
382da6c28aamw	if (vn_openat(name, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0, rootdir,
383da6c28aamw	    -1) != 0)
384ea8dc4beschrock		return ((void *)-1UL);
385ea8dc4beschrock
386ea8dc4beschrock	file = umem_zalloc(sizeof (struct _buf), UMEM_NOFAIL);
387ea8dc4beschrock	file->_fd = (intptr_t)vp;
388ea8dc4beschrock	return (file);
389ea8dc4beschrock}
390ea8dc4beschrock
391ea8dc4beschrockint
392ea8dc4beschrockkobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off)
393ea8dc4beschrock{
394ea8dc4beschrock	ssize_t resid;
395ea8dc4beschrock
396ea8dc4beschrock	vn_rdwr(UIO_READ, (vnode_t *)file->_fd, buf, size, (offset_t)off,
397ea8dc4beschrock	    UIO_SYSSPACE, 0, 0, 0, &resid);
398ea8dc4beschrock
399b1b8ab3lling	return (size - resid);
400ea8dc4beschrock}
401ea8dc4beschrock
402ea8dc4beschrockvoid
403ea8dc4beschrockkobj_close_file(struct _buf *file)
404ea8dc4beschrock{
405ea8dc4beschrock	vn_close((vnode_t *)file->_fd);
406ea8dc4beschrock	umem_free(file, sizeof (struct _buf));
407ea8dc4beschrock}
408ea8dc4beschrock
409ea8dc4beschrockint
410b1b8ab3llingkobj_get_filesize(struct _buf *file, uint64_t *size)
411ea8dc4beschrock{
412ea8dc4beschrock	struct stat64 st;
413b1b8ab3lling	vnode_t *vp = (vnode_t *)file->_fd;
414b1b8ab3lling
415ea8dc4beschrock	if (fstat64(vp->v_fd, &st) == -1) {
416ea8dc4beschrock		vn_close(vp);
417ea8dc4beschrock		return (errno);
418ea8dc4beschrock	}
419b1b8ab3lling	*size = st.st_size;
420ea8dc4beschrock	return (0);
421ea8dc4beschrock}
422ea8dc4beschrock
423ea8dc4beschrock/*
424ea8dc4beschrock * =========================================================================
425fa9e406ahrens * kernel emulation setup & teardown
426fa9e406ahrens * =========================================================================
427fa9e406ahrens */
428fa9e406ahrensstatic int
429fa9e406ahrensumem_out_of_memory(void)
430fa9e406ahrens{
431fa9e406ahrens	char errmsg[] = "out of memory -- generating core dump\n";
432fa9e406ahrens
433fa9e406ahrens	write(fileno(stderr), errmsg, sizeof (errmsg));
434fa9e406ahrens	abort();
435fa9e406ahrens	return (0);
436fa9e406ahrens}
437fa9e406ahrens
438fa9e406ahrensvoid
439fa9e406ahrenskernel_init(int mode)
440fa9e406ahrens{
4413b2aab1Matthew Ahrens	extern uint_t rrw_tsd_key;
4423b2aab1Matthew Ahrens
443fa9e406ahrens	umem_nofail_callback(umem_out_of_memory);
444fa9e406ahrens
445fa9e406ahrens	physmem = sysconf(_SC_PHYS_PAGES);
446fa9e406ahrens
447fa9e406ahrens	dprintf("physmem = %llu pages (%.2f GB)\n", physmem,
448fa9e406ahrens	    (double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
449fa9e406ahrens
4503ad6c7fVictor Latushkin	(void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
451e0f1c0aOlaf Faaland	    (mode & FWRITE) ? get_system_hostid() : 0);
4529517395ek
45388b7b0fMatthew Ahrens	system_taskq_init();
45488b7b0fMatthew Ahrens
455283b846George.Wilson	mutex_init(&cpu_lock, NULL, MUTEX_DEFAULT, NULL);
456283b846George.Wilson
457fa9e406ahrens	spa_init(mode);
4583b2aab1Matthew Ahrens
4593b2aab1Matthew Ahrens	tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
460fa9e406ahrens}
461fa9e406ahrens
462fa9e406ahrensvoid
463fa9e406ahrenskernel_fini(void)
464fa9e406ahrens{
465fa9e406ahrens	spa_fini();
46617f17c2bonwick
467d20e665Ricardo M. Correia	system_taskq_fini();
468fa9e406ahrens}
469c9431faahl
4706f79381Pavel Zakharov/* ARGSUSED */
4716f79381Pavel Zakharovuint32_t
4726f79381Pavel Zakharovzone_get_hostid(void *zonep)
4736f79381Pavel Zakharov{
4746f79381Pavel Zakharov	/*
4756f79381Pavel Zakharov	 * We're emulating the system's hostid in userland.
4766f79381Pavel Zakharov	 */
4776f79381Pavel Zakharov	return (strtoul(hw_serial, NULL, 10));
4786f79381Pavel Zakharov}
4796f79381Pavel Zakharov
480c9431faahlint
481c9431faahlz_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
482c9431faahl{
483c9431faahl	int ret;
484c9431faahl	uLongf len = *dstlen;
485c9431faahl
486c9431faahl	if ((ret = uncompress(dst, &len, src, srclen)) == Z_OK)
487c9431faahl		*dstlen = (size_t)len;
488c9431faahl
489c9431faahl	return (ret);
490c9431faahl}
491c9431faahl
492c9431faahlint
493c9431faahlz_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen,
494c9431faahl    int level)
495c9431faahl{
496c9431faahl	int ret;
497c9431faahl	uLongf len = *dstlen;
498c9431faahl
499c9431faahl	if ((ret = compress2(dst, &len, src, srclen, level)) == Z_OK)
500c9431faahl		*dstlen = (size_t)len;
501c9431faahl
502c9431faahl	return (ret);
503c9431faahl}
504ecd6cf8marks
505ecd6cf8marksint
506ecd6cf8markszfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
507ecd6cf8marks{
508ecd6cf8marks	return (0);
509ecd6cf8marks}
510ecd6cf8marks
511ecd6cf8marksint
512ecd6cf8markszfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
513ecd6cf8marks{
514ecd6cf8marks	return (0);
515ecd6cf8marks}
516ecd6cf8marks
517ecd6cf8marksint
518ecd6cf8markszfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
519ecd6cf8marks{
520ecd6cf8marks	return (0);
521ecd6cf8marks}
522e0d35c4marks
523c99e4bdChris Kirby/* ARGSUSED */
524c99e4bdChris Kirbyint
525a7f53a5Chris Kirbyzfs_onexit_fd_hold(int fd, minor_t *minorp)
526a7f53a5Chris Kirby{
527a7f53a5Chris Kirby	*minorp = 0;
528a7f53a5Chris Kirby	return (0);
529a7f53a5Chris Kirby}
530a7f53a5Chris Kirby
531a7f53a5Chris Kirby/* ARGSUSED */
532a7f53a5Chris Kirbyvoid
533a7f53a5Chris Kirbyzfs_onexit_fd_rele(int fd)
534a7f53a5Chris Kirby{
535a7f53a5Chris Kirby}
536a7f53a5Chris Kirby
537a7f53a5Chris Kirby/* ARGSUSED */
538a7f53a5Chris Kirbyint
539a7f53a5Chris Kirbyzfs_onexit_add_cb(minor_t minor, void (*func)(void *), void *data,
540c99e4bdChris Kirby    uint64_t *action_handle)
541c99e4bdChris Kirby{
542c99e4bdChris Kirby	return (0);
543c99e4bdChris Kirby}
544c99e4bdChris Kirby
545c99e4bdChris Kirby/* ARGSUSED */
546c99e4bdChris Kirbyint
547a7f53a5Chris Kirbyzfs_onexit_del_cb(minor_t minor, uint64_t action_handle, boolean_t fire)
548c99e4bdChris Kirby{
549c99e4bdChris Kirby	return (0);
550c99e4bdChris Kirby}
551c99e4bdChris Kirby
552c99e4bdChris Kirby/* ARGSUSED */
553c99e4bdChris Kirbyint
554a7f53a5Chris Kirbyzfs_onexit_cb_data(minor_t minor, uint64_t action_handle, void **data)
555c99e4bdChris Kirby{
556c99e4bdChris Kirby	return (0);
557c99e4bdChris Kirby}
55831d7e8fGeorge Wilson
55931d7e8fGeorge Wilsonvoid
56031d7e8fGeorge Wilsonbioinit(buf_t *bp)
56131d7e8fGeorge Wilson{
56231d7e8fGeorge Wilson	bzero(bp, sizeof (buf_t));
56331d7e8fGeorge Wilson}
56431d7e8fGeorge Wilson
56531d7e8fGeorge Wilsonvoid
56631d7e8fGeorge Wilsonbiodone(buf_t *bp)
56731d7e8fGeorge Wilson{
56831d7e8fGeorge Wilson	if (bp->b_iodone != NULL) {
56931d7e8fGeorge Wilson		(*(bp->b_iodone))(bp);
57031d7e8fGeorge Wilson		return;
57131d7e8fGeorge Wilson	}
57231d7e8fGeorge Wilson	ASSERT((bp->b_flags & B_DONE) == 0);
57331d7e8fGeorge Wilson	bp->b_flags |= B_DONE;
57431d7e8fGeorge Wilson}
57531d7e8fGeorge Wilson
57631d7e8fGeorge Wilsonvoid
57731d7e8fGeorge Wilsonbioerror(buf_t *bp, int error)
57831d7e8fGeorge Wilson{
57931d7e8fGeorge Wilson	ASSERT(bp != NULL);
58031d7e8fGeorge Wilson	ASSERT(error >= 0);
58131d7e8fGeorge Wilson
58231d7e8fGeorge Wilson	if (error != 0) {
58331d7e8fGeorge Wilson		bp->b_flags |= B_ERROR;
58431d7e8fGeorge Wilson	} else {
58531d7e8fGeorge Wilson		bp->b_flags &= ~B_ERROR;
58631d7e8fGeorge Wilson	}
58731d7e8fGeorge Wilson	bp->b_error = error;
58831d7e8fGeorge Wilson}
58931d7e8fGeorge Wilson
59031d7e8fGeorge Wilson
59131d7e8fGeorge Wilsonint
59231d7e8fGeorge Wilsongeterror(struct buf *bp)
59331d7e8fGeorge Wilson{
59431d7e8fGeorge Wilson	int error = 0;
59531d7e8fGeorge Wilson
59631d7e8fGeorge Wilson	if (bp->b_flags & B_ERROR) {
59731d7e8fGeorge Wilson		error = bp->b_error;
59831d7e8fGeorge Wilson		if (!error)
59931d7e8fGeorge Wilson			error = EIO;
60031d7e8fGeorge Wilson	}
60131d7e8fGeorge Wilson	return (error);
60231d7e8fGeorge Wilson}
603eb63303Tom Caputi
604eb63303Tom Caputiint
605eb63303Tom Caputicrypto_create_ctx_template(crypto_mechanism_t *mech,
606eb63303Tom Caputi    crypto_key_t *key, crypto_ctx_template_t *tmpl, int kmflag)
607eb63303Tom Caputi{
608eb63303Tom Caputi	return (0);
609eb63303Tom Caputi}
610eb63303Tom Caputi
611eb63303Tom Caputicrypto_mech_type_t
612eb63303Tom Caputicrypto_mech2id(crypto_mech_name_t name)
613eb63303Tom Caputi{
614eb63303Tom Caputi	return (CRYPTO_MECH_INVALID);
615eb63303Tom Caputi}
616eb63303Tom Caputi
617eb63303Tom Caputiint
618eb63303Tom Caputicrypto_mac(crypto_mechanism_t *mech, crypto_data_t *data,
619eb63303Tom Caputi    crypto_key_t *key, crypto_ctx_template_t impl,
620eb63303Tom Caputi    crypto_data_t *mac, crypto_call_req_t *cr)
621eb63303Tom Caputi{
622eb63303Tom Caputi	return (0);
623eb63303Tom Caputi}
624eb63303Tom Caputi
625eb63303Tom Caputiint
626eb63303Tom Caputicrypto_encrypt(crypto_mechanism_t *mech, crypto_data_t *plaintext,
627eb63303Tom Caputi    crypto_key_t *key, crypto_ctx_template_t tmpl,
628eb63303Tom Caputi    crypto_data_t *ciphertext, crypto_call_req_t *cr)
629eb63303Tom Caputi{
630eb63303Tom Caputi	return (0);
631eb63303Tom Caputi}
632eb63303Tom Caputi
633eb63303Tom Caputi/* This could probably be a weak reference */
634