kernel.c revision 095bcd6622e3b3520eb3b71039a3be5cfab25b74
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <assert.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#include <sys/processor.h>
#include <sys/zfs_context.h>
#include <sys/systeminfo.h>
/*
* Emulation of kernel services in userland.
*/
char hw_serial[HW_HOSTID_LEN];
"userland", "libzpool", "1", "1", "na"
};
/*
* =========================================================================
* threads
* =========================================================================
*/
/*ARGSUSED*/
{
&tid) == 0);
}
/*
* =========================================================================
* kstats
* =========================================================================
*/
/*ARGSUSED*/
kstat_t *
{
return (NULL);
}
/*ARGSUSED*/
void
{}
/*ARGSUSED*/
void
{}
/*
* =========================================================================
* mutexes
* =========================================================================
*/
void
{
}
void
{
}
void
{
}
int
{
return (1);
} else {
return (0);
}
}
void
{
}
void *
{
}
/*
* =========================================================================
* rwlocks
* =========================================================================
*/
/*ARGSUSED*/
void
{
}
void
{
}
void
{
else
}
void
{
}
int
{
int rv;
else
if (rv == 0) {
return (1);
}
return (0);
}
/*ARGSUSED*/
int
{
return (0);
}
/*
* =========================================================================
* condition variables
* =========================================================================
*/
/*ARGSUSED*/
void
{
}
void
{
}
void
{
}
{
int error;
top:
if (delta <= 0)
return (-1);
return (-1);
goto top;
return (1);
}
void
{
}
void
{
}
/*
* =========================================================================
* vnode operations
* =========================================================================
*/
/*
* Note: for the xxxat() versions of these functions, we assume that the
* starting vp is always rootdir (which is true for spa_directory.c, the only
* ZFS consumer of these interfaces). We assert this is true, and then emulate
* them by adding '/' in front of the path.
*/
/*ARGSUSED*/
int
{
int fd;
int old_umask;
char realpath[MAXPATHLEN];
/*
* If we're accessing a real disk from userland, we need to use
* the character interface to avoid caching. This is particularly
* important if we're trying to look at a real in-kernel storage
* pool from userland, e.g. via zdb, because otherwise we won't
* see the changes occurring under the segmap cache.
* On the other hand, the stupid character device returns zero
* for its size. So -- gag -- we open the block device to get
* its size, and remember it for subsequent VOP_GETATTR().
*/
char *dsk;
if (fd == -1)
return (errno);
return (errno);
}
dsk + 1);
} else {
return (errno);
}
/*
* The construct 'flags - FREAD' conveniently maps combinations of
* FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
*/
if (fd == -1)
return (errno);
return (errno);
}
return (0);
}
/*ARGSUSED*/
int
{
int ret;
/* fd ignored for now, need if want to simulate nbmand support */
return (ret);
}
/*ARGSUSED*/
int
{
} else {
/*
* To simulate partial disk writes, we split writes into two
* system calls so that the process can be killed in between.
*/
}
if (iolen == -1)
return (errno);
if (residp)
return (EIO);
return (0);
}
void
{
}
/*
* At a minimum we need to update the size since vdev_reopen()
* will no longer call vn_openat().
*/
int
{
return (errno);
}
return (0);
}
#ifdef ZFS_DEBUG
/*
* =========================================================================
* Figure out which debugging statements to print
* =========================================================================
*/
static char *dprintf_string;
static int dprintf_print_all;
int
dprintf_find_string(const char *string)
{
char *tmp_str = dprintf_string;
/*
* Find out if this is a string we want to print.
*/
return (1);
tmp_str++; /* Get rid of , */
}
return (0);
}
void
{
int i, j;
/*
* Debugging can be specified two ways: by setting the
* environment variable ZFS_DEBUG, or by including a
* "debug=..." argument on the command line. The command
* line setting overrides the environment variable.
*/
for (i = 1; i < *argc; i++) {
/* First look for a command line argument */
/* Remove from args */
for (j = i; j < *argc; j++)
(*argc)--;
}
}
if (dprintf_string == NULL) {
/* Look for ZFS_DEBUG environment variable */
}
/*
* Are we just turning on all debugging?
*/
if (dprintf_find_string("on"))
dprintf_print_all = 1;
}
/*
* =========================================================================
* debug printfs
* =========================================================================
*/
void
{
const char *newfile;
/*
* Get rid of annoying "../common/" prefix to filename.
*/
} else {
}
if (dprintf_print_all ||
/* Print out just the function name if requested */
if (dprintf_find_string("pid"))
if (dprintf_find_string("tid"))
if (dprintf_find_string("cpu"))
if (dprintf_find_string("time"))
if (dprintf_find_string("long"))
}
}
#endif /* ZFS_DEBUG */
/*
* =========================================================================
* cmn_err() and panic()
* =========================================================================
*/
void
{
abort(); /* think of it as a "user-level crash dump" */
}
void
{
}
void
{
}
}
/*PRINTFLIKE2*/
void
{
}
/*
* =========================================================================
* kobj interfaces
* =========================================================================
*/
struct _buf *
kobj_open_file(char *name)
{
/* set vp as the _fd field of the file */
-1) != 0)
return ((void *)-1UL);
return (file);
}
int
{
UIO_SYSSPACE, 0, 0, 0, &resid);
}
void
{
}
int
{
return (errno);
}
return (0);
}
/*
* =========================================================================
* misc routines
* =========================================================================
*/
void
{
}
/*
* Find highest one bit set.
* Returns bit number + 1 of highest bit that is set, otherwise returns 0.
* High order bit is 31 (or 63 in _LP64 kernel).
*/
int
{
register int h = 1;
if (i == 0)
return (0);
#ifdef _LP64
if (i & 0xffffffff00000000ul) {
h += 32; i >>= 32;
}
#endif
if (i & 0xffff0000) {
h += 16; i >>= 16;
}
if (i & 0xff00) {
h += 8; i >>= 8;
}
if (i & 0xf0) {
h += 4; i >>= 4;
}
if (i & 0xc) {
h += 2; i >>= 2;
}
if (i & 0x2) {
h += 1;
}
return (h);
}
static int
{
while (resid != 0) {
}
return (0);
}
int
{
}
int
{
}
int
{
char *end;
if (*result == 0)
return (errno);
return (0);
}
/*
* =========================================================================
* kernel emulation setup & teardown
* =========================================================================
*/
static int
umem_out_of_memory(void)
{
char errmsg[] = "out of memory -- generating core dump\n";
abort();
return (0);
}
void
kernel_init(int mode)
{
}
void
kernel_fini(void)
{
spa_fini();
random_fd = -1;
urandom_fd = -1;
}
int
{
int ret;
return (ret);
}
int
int level)
{
int ret;
return (ret);
}
{
return (0);
}
{
return (0);
}
int
{
return (0);
}
gid_t *
{
return (NULL);
}
int
{
return (0);
}
int
{
return (0);
}
int
{
return (0);
}
ksid_lookupdomain(const char *dom)
{
return (kd);
}
void
{
}
/*
* Do not change the length of the returned string; it must be freed
* with strfree().
*/
char *
kmem_asprintf(const char *fmt, ...)
{
int size;
char *buf;
return (buf);
}