fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
b3d32f0ceb59362ba287dcfd6de471e98bfc7fa9Bryan Cantrill * Copyright (c) 2013, Joyent, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Emulation of kernel services in userland.
df15e419cb7359ba56ddddab9045e438d89e7cbcMatthew Ahrens/* If set, all blocks read will be copied to the specified directory. */
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams/* this only exists to have its address taken */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
8fc922875ed266f52ccd5cc6f973b9ad0839c710Eli Rosenthalzk_thread_create(void (*func)(), void *arg, uint64_t len)
fa9e4066f08beec538e775443c5be79dd423fcabahrens VERIFY(thr_create(0, 0, (void *(*)(void *))func, arg, THR_DETACHED,
44cb6abc89aa591c23f5e58296c6d2a29302344abmc * =========================================================================
44cb6abc89aa591c23f5e58296c6d2a29302344abmc * =========================================================================
44cb6abc89aa591c23f5e58296c6d2a29302344abmc/*ARGSUSED*/
c3a66015199e1814c2af8f7e6929af2004302e7eMatthew Ahrenskstat_create(const char *module, int instance, const char *name,
c3a66015199e1814c2af8f7e6929af2004302e7eMatthew Ahrens const char *class, uchar_t type, ulong_t ndata, uchar_t ks_flag)
8363e80ae72609660f6090766ca8c2c18aa53f0cGeorge Wilsonkstat_named_init(kstat_named_t *knp, const char *name, uchar_t type)
44cb6abc89aa591c23f5e58296c6d2a29302344abmc/*ARGSUSED*/
44cb6abc89aa591c23f5e58296c6d2a29302344abmc/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrensrw_init(krwlock_t *rwlp, char *name, int type, void *arg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (rv == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * condition variables
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrenscv_init(kcondvar_t *cv, char *name, int type, void *arg)
fa9e4066f08beec538e775443c5be79dd423fcabahrenscv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhalcv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
41c6413cb54bf338d7a59ed789ec2e0e44c35e6fGeorge Wilson ASSERT(flag == 0 || flag == CALLOUT_FLAG_ABSOLUTE);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal error = cond_reltimedwait(cv, &mp->m_lock, &ts);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * vnode operations
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Note: for the xxxat() versions of these functions, we assume that the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * starting vp is always rootdir (which is true for spa_directory.c, the only
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ZFS consumer of these interfaces). We assert this is true, and then emulate
fa9e4066f08beec538e775443c5be79dd423fcabahrens * them by adding '/' in front of the path.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrensvn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're accessing a real disk from userland, we need to use
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the character interface to avoid caching. This is particularly
fa9e4066f08beec538e775443c5be79dd423fcabahrens * important if we're trying to look at a real in-kernel storage
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pool from userland, e.g. via zdb, because otherwise we won't
fa9e4066f08beec538e775443c5be79dd423fcabahrens * see the changes occurring under the segmap cache.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * On the other hand, the stupid character device returns zero
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for its size. So -- gag -- we open the block device to get
fa9e4066f08beec538e775443c5be79dd423fcabahrens * its size, and remember it for subsequent VOP_GETATTR().
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!(flags & FCREAT) && stat64(realpath, &st) == -1)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The construct 'flags - FREAD' conveniently maps combinations of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
df15e419cb7359ba56ddddab9045e438d89e7cbcMatthew Ahrens dump_fd = open64(dumppath, O_CREAT | O_WRONLY, 0666);
fa9e4066f08beec538e775443c5be79dd423fcabahrens *vpp = vp = umem_zalloc(sizeof (vnode_t), UMEM_NOFAIL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrensvn_openat(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2,
fa9e4066f08beec538e775443c5be79dd423fcabahrens char *realpath = umem_alloc(strlen(path) + 2, UMEM_NOFAIL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* fd ignored for now, need if want to simulate nbmand support */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = vn_open(realpath, x1, flags, mode, vpp, x2, x3);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrensvn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset,
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp)
df15e419cb7359ba56ddddab9045e438d89e7cbcMatthew Ahrens pwrite64(vp->v_dump_fd, addr, iolen, offset);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * To simulate partial disk writes, we split writes into two
fa9e4066f08beec538e775443c5be79dd423fcabahrens * system calls so that the process can be killed in between.
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden split = (sectors > 0 ? rand() % sectors : 0) <<
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * At a minimum we need to update the size since vdev_reopen()
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * will no longer call vn_openat().
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Figure out which debugging statements to print
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Find out if this is a string we want to print.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * String format: file1.c,function_name1,file2.c,file3.c
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Debugging can be specified two ways: by setting the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * environment variable ZFS_DEBUG, or by including a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * "debug=..." argument on the command line. The command
fa9e4066f08beec538e775443c5be79dd423fcabahrens * line setting overrides the environment variable.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* First look for a command line argument */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Remove from args */
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (j = i; j < *argc; j++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Look for ZFS_DEBUG environment variable */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Are we just turning on all debugging?
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * debug printfs
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Get rid of annoying "../common/" prefix to filename.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Print out just the function name if requested */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* ZFS_DEBUG */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * cmn_err() and panic()
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic char ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" };
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic char ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" };
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ce != CE_NOTE) { /* suppress noise in userland stress testing */
0125049cd6136d1d2ca9e982382a915b6d7916ceahrens/*PRINTFLIKE2*/
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * =========================================================================
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * kobj interfaces
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * =========================================================================
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock /* set vp as the _fd field of the file */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (vn_openat(name, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0, rootdir,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return ((void *)-1UL);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock file = umem_zalloc(sizeof (struct _buf), UMEM_NOFAIL);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockkobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock vn_rdwr(UIO_READ, (vnode_t *)file->_fd, buf, size, (offset_t)off,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * misc routines
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Find highest one bit set.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
bf16b11e8deb633dd6c4296d46e92399d1582df4Matthew Ahrens if (i & 0xffffffff00000000ULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i & 0xffff0000) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i & 0xff00) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i & 0xf0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i & 0xc) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i & 0x2) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (h);
17f17c2df4ca603e787c5fc03b7af83519edfd2cbonwickrandom_get_bytes_common(uint8_t *ptr, size_t len, int fd)
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (resid != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
17f17c2df4ca603e787c5fc03b7af83519edfd2cbonwick return (random_get_bytes_common(ptr, len, random_fd));
17f17c2df4ca603e787c5fc03b7af83519edfd2cbonwick return (random_get_bytes_common(ptr, len, urandom_fd));
95173954d2b811ceb583a9012c3b16e1d0dd6438ekddi_strtoul(const char *hw_serial, char **nptr, int base, unsigned long *result)
95173954d2b811ceb583a9012c3b16e1d0dd6438ek if (*result == 0)
95173954d2b811ceb583a9012c3b16e1d0dd6438ek return (0);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaumddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result)
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson/* ARGSUSED */
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilsoncyclic_add(cyc_handler_t *hdlr, cyc_time_t *when)
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson/* ARGSUSED */
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson/* ARGSUSED */
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilsoncyclic_reprogram(cyclic_id_t id, hrtime_t expiration)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens * kernel emulation setup & teardown
fa9e4066f08beec538e775443c5be79dd423fcabahrens * =========================================================================
fa9e4066f08beec538e775443c5be79dd423fcabahrens char errmsg[] = "out of memory -- generating core dump\n";
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
3ad6c7f96bc462dcbd2a112df698038f6764eabcVictor Latushkin (void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
17f17c2df4ca603e787c5fc03b7af83519edfd2cbonwick VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1);
17f17c2df4ca603e787c5fc03b7af83519edfd2cbonwick VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1);
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson mutex_init(&cpu_lock, NULL, MUTEX_DEFAULT, NULL);
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlz_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlz_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen,
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl if ((ret = compress2(dst, &len, src, srclen, level)) == Z_OK)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarkszfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks return (0);
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrens * Do not change the length of the returned string; it must be freed
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrens * with strfree().
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby/* ARGSUSED */
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby/* ARGSUSED */
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby/* ARGSUSED */
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirbyzfs_onexit_add_cb(minor_t minor, void (*func)(void *), void *data,
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby/* ARGSUSED */
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirbyzfs_onexit_del_cb(minor_t minor, uint64_t action_handle, boolean_t fire)
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby/* ARGSUSED */