2010-05-18 02:18:00 +04:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 08:38:26 +04:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
|
|
|
* For details, see <http://github.com/behlendorf/spl/>.
|
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 08:38:26 +04:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 08:38:26 +04:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-18 02:18:00 +04:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************
|
|
|
|
* Solaris Porting Layer (SPL) Generic Implementation.
|
|
|
|
\*****************************************************************************/
|
2008-05-26 08:38:26 +04:00
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#include <sys/sysmacros.h>
|
2009-02-19 22:26:17 +03:00
|
|
|
#include <sys/systeminfo.h>
|
2008-03-14 03:04:01 +03:00
|
|
|
#include <sys/vmsystm.h>
|
|
|
|
#include <sys/vnode.h>
|
2008-03-14 23:56:26 +03:00
|
|
|
#include <sys/kmem.h>
|
2008-05-06 00:18:49 +04:00
|
|
|
#include <sys/mutex.h>
|
2009-09-26 01:14:35 +04:00
|
|
|
#include <sys/rwlock.h>
|
2009-01-06 02:08:03 +03:00
|
|
|
#include <sys/taskq.h>
|
2008-04-01 00:42:36 +04:00
|
|
|
#include <sys/debug.h>
|
2008-04-19 03:39:58 +04:00
|
|
|
#include <sys/proc.h>
|
2008-05-09 03:21:47 +04:00
|
|
|
#include <sys/kstat.h>
|
2008-06-04 01:20:18 +04:00
|
|
|
#include <sys/utsname.h>
|
2009-07-10 21:56:32 +04:00
|
|
|
#include <sys/file.h>
|
2008-04-12 08:27:59 +04:00
|
|
|
#include <linux/kmod.h>
|
2010-06-12 01:37:46 +04:00
|
|
|
#include <linux/proc_compat.h>
|
2008-02-27 22:09:51 +03:00
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
#ifdef DEBUG_SUBSYSTEM
|
|
|
|
#undef DEBUG_SUBSYSTEM
|
|
|
|
#endif
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
#define DEBUG_SUBSYSTEM S_GENERIC
|
2008-04-12 08:27:59 +04:00
|
|
|
|
2009-03-18 00:55:59 +03:00
|
|
|
char spl_version[16] = "SPL v" SPL_META_VERSION;
|
2008-04-24 21:41:23 +04:00
|
|
|
|
2008-04-21 21:29:47 +04:00
|
|
|
long spl_hostid = 0;
|
2008-04-12 08:27:59 +04:00
|
|
|
EXPORT_SYMBOL(spl_hostid);
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2009-02-19 22:26:17 +03:00
|
|
|
char hw_serial[HW_HOSTID_LEN] = "<none>";
|
2008-04-21 21:29:47 +04:00
|
|
|
EXPORT_SYMBOL(hw_serial);
|
2008-02-27 22:09:51 +03:00
|
|
|
|
2010-06-12 01:37:46 +04:00
|
|
|
proc_t p0 = { 0 };
|
2008-02-27 22:09:51 +03:00
|
|
|
EXPORT_SYMBOL(p0);
|
2008-02-28 00:56:51 +03:00
|
|
|
|
2009-02-26 00:20:40 +03:00
|
|
|
#ifndef HAVE_KALLSYMS_LOOKUP_NAME
|
2009-05-20 21:08:37 +04:00
|
|
|
kallsyms_lookup_name_t spl_kallsyms_lookup_name_fn = SYMBOL_POISON;
|
2009-02-26 00:20:40 +03:00
|
|
|
#endif
|
|
|
|
|
2008-03-07 02:12:55 +03:00
|
|
|
int
|
|
|
|
highbit(unsigned long i)
|
|
|
|
{
|
|
|
|
register int h = 1;
|
2008-08-12 02:13:47 +04:00
|
|
|
ENTRY;
|
2008-03-07 02:12:55 +03:00
|
|
|
|
|
|
|
if (i == 0)
|
2008-04-19 03:39:58 +04:00
|
|
|
RETURN(0);
|
2008-03-07 02:12:55 +03:00
|
|
|
#if BITS_PER_LONG == 64
|
|
|
|
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;
|
|
|
|
}
|
2008-04-19 03:39:58 +04:00
|
|
|
RETURN(h);
|
2008-03-07 02:12:55 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(highbit);
|
|
|
|
|
2008-08-12 02:42:04 +04:00
|
|
|
/*
|
2008-11-03 23:34:17 +03:00
|
|
|
* Implementation of 64 bit division for 32-bit machines.
|
2008-08-12 02:42:04 +04:00
|
|
|
*/
|
2008-11-03 23:34:17 +03:00
|
|
|
#if BITS_PER_LONG == 32
|
2010-06-03 09:01:14 +04:00
|
|
|
uint64_t
|
|
|
|
__udivdi3(uint64_t dividend, uint64_t divisor)
|
2008-08-12 02:42:04 +04:00
|
|
|
{
|
2009-05-20 21:08:37 +04:00
|
|
|
#if defined(HAVE_DIV64_64) /* 2.6.22 - 2.6.25 API */
|
2008-11-03 23:34:17 +03:00
|
|
|
return div64_64(dividend, divisor);
|
2009-05-20 21:08:37 +04:00
|
|
|
#elif defined(HAVE_DIV64_U64) /* 2.6.26 - 2.6.x API */
|
|
|
|
return div64_u64(dividend, divisor);
|
2008-11-03 23:34:17 +03:00
|
|
|
#else
|
2009-05-20 21:08:37 +04:00
|
|
|
/* Implementation from 2.6.30 kernel */
|
2008-08-12 02:42:04 +04:00
|
|
|
uint32_t high, d;
|
|
|
|
|
|
|
|
high = divisor >> 32;
|
|
|
|
if (high) {
|
|
|
|
unsigned int shift = fls(high);
|
|
|
|
|
|
|
|
d = divisor >> shift;
|
|
|
|
dividend >>= shift;
|
|
|
|
} else
|
|
|
|
d = divisor;
|
|
|
|
|
2009-12-02 02:53:28 +03:00
|
|
|
do_div(dividend, d);
|
|
|
|
|
|
|
|
return dividend;
|
2009-05-20 21:08:37 +04:00
|
|
|
#endif /* HAVE_DIV64_64, HAVE_DIV64_U64 */
|
2008-11-03 23:34:17 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__udivdi3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of 64 bit modulo for 32-bit machines.
|
|
|
|
*/
|
2010-06-03 09:01:14 +04:00
|
|
|
uint64_t
|
|
|
|
__umoddi3(uint64_t dividend, uint64_t divisor)
|
2008-11-03 23:34:17 +03:00
|
|
|
{
|
2010-06-03 09:01:14 +04:00
|
|
|
return (dividend - (divisor * __udivdi3(dividend, divisor)));
|
2008-08-12 02:42:04 +04:00
|
|
|
}
|
2008-11-03 23:34:17 +03:00
|
|
|
EXPORT_SYMBOL(__umoddi3);
|
2009-05-20 21:08:37 +04:00
|
|
|
#endif /* BITS_PER_LONG */
|
2008-08-12 02:42:04 +04:00
|
|
|
|
2009-01-13 20:30:59 +03:00
|
|
|
/* NOTE: The strtoxx behavior is solely based on my reading of the Solaris
|
|
|
|
* ddi_strtol(9F) man page. I have not verified the behavior of these
|
|
|
|
* functions against their Solaris counterparts. It is possible that I
|
2009-05-20 21:08:37 +04:00
|
|
|
* may have misinterpreted the man page or the man page is incorrect.
|
2009-01-13 20:30:59 +03:00
|
|
|
*/
|
2008-12-06 03:23:57 +03:00
|
|
|
int ddi_strtoul(const char *, char **, int, unsigned long *);
|
|
|
|
int ddi_strtol(const char *, char **, int, long *);
|
|
|
|
int ddi_strtoull(const char *, char **, int, unsigned long long *);
|
|
|
|
int ddi_strtoll(const char *, char **, int, long long *);
|
|
|
|
|
|
|
|
#define define_ddi_strtoux(type, valtype) \
|
|
|
|
int ddi_strtou##type(const char *str, char **endptr, \
|
2009-01-13 20:30:59 +03:00
|
|
|
int base, valtype *result) \
|
2008-12-06 03:23:57 +03:00
|
|
|
{ \
|
2009-01-13 20:30:59 +03:00
|
|
|
valtype last_value, value = 0; \
|
|
|
|
char *ptr = (char *)str; \
|
|
|
|
int flag = 1, digit; \
|
|
|
|
\
|
|
|
|
if (strlen(ptr) == 0) \
|
|
|
|
return EINVAL; \
|
|
|
|
\
|
|
|
|
/* Auto-detect base based on prefix */ \
|
|
|
|
if (!base) { \
|
|
|
|
if (str[0] == '0') { \
|
|
|
|
if (tolower(str[1])=='x' && isxdigit(str[2])) { \
|
|
|
|
base = 16; /* hex */ \
|
|
|
|
ptr += 2; \
|
|
|
|
} else if (str[1] >= '0' && str[1] < 8) { \
|
|
|
|
base = 8; /* octal */ \
|
|
|
|
ptr += 1; \
|
|
|
|
} else { \
|
|
|
|
return EINVAL; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
base = 10; /* decimal */ \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
while (1) { \
|
|
|
|
if (isdigit(*ptr)) \
|
|
|
|
digit = *ptr - '0'; \
|
|
|
|
else if (isalpha(*ptr)) \
|
|
|
|
digit = tolower(*ptr) - 'a' + 10; \
|
|
|
|
else \
|
|
|
|
break; \
|
|
|
|
\
|
|
|
|
if (digit >= base) \
|
|
|
|
break; \
|
2008-12-06 03:23:57 +03:00
|
|
|
\
|
2009-01-13 20:30:59 +03:00
|
|
|
last_value = value; \
|
|
|
|
value = value * base + digit; \
|
|
|
|
if (last_value > value) /* Overflow */ \
|
|
|
|
return ERANGE; \
|
2008-12-06 03:23:57 +03:00
|
|
|
\
|
2009-01-13 20:30:59 +03:00
|
|
|
flag = 1; \
|
|
|
|
ptr++; \
|
2008-12-06 03:23:57 +03:00
|
|
|
} \
|
|
|
|
\
|
2009-01-13 20:30:59 +03:00
|
|
|
if (flag) \
|
|
|
|
*result = value; \
|
|
|
|
\
|
|
|
|
if (endptr) \
|
|
|
|
*endptr = (char *)(flag ? ptr : str); \
|
|
|
|
\
|
|
|
|
return 0; \
|
2008-12-06 03:23:57 +03:00
|
|
|
} \
|
|
|
|
|
|
|
|
#define define_ddi_strtox(type, valtype) \
|
|
|
|
int ddi_strto##type(const char *str, char **endptr, \
|
|
|
|
int base, valtype *result) \
|
2009-01-13 20:30:59 +03:00
|
|
|
{ \
|
|
|
|
int rc; \
|
2008-12-06 03:23:57 +03:00
|
|
|
\
|
|
|
|
if (*str == '-') { \
|
2009-01-13 20:30:59 +03:00
|
|
|
rc = ddi_strtou##type(str + 1, endptr, base, result); \
|
|
|
|
if (!rc) { \
|
|
|
|
if (*endptr == str + 1) \
|
|
|
|
*endptr = (char *)str; \
|
|
|
|
else \
|
|
|
|
*result = -*result; \
|
|
|
|
} \
|
2008-12-06 03:23:57 +03:00
|
|
|
} else { \
|
2009-01-13 20:30:59 +03:00
|
|
|
rc = ddi_strtou##type(str, endptr, base, result); \
|
2008-12-06 03:23:57 +03:00
|
|
|
} \
|
|
|
|
\
|
2009-01-13 20:30:59 +03:00
|
|
|
return rc; \
|
|
|
|
}
|
2008-12-06 03:23:57 +03:00
|
|
|
|
|
|
|
define_ddi_strtoux(l, unsigned long)
|
|
|
|
define_ddi_strtox(l, long)
|
|
|
|
define_ddi_strtoux(ll, unsigned long long)
|
|
|
|
define_ddi_strtox(ll, long long)
|
|
|
|
|
2008-03-13 00:33:28 +03:00
|
|
|
EXPORT_SYMBOL(ddi_strtoul);
|
2008-12-06 03:23:57 +03:00
|
|
|
EXPORT_SYMBOL(ddi_strtol);
|
|
|
|
EXPORT_SYMBOL(ddi_strtoll);
|
|
|
|
EXPORT_SYMBOL(ddi_strtoull);
|
2008-03-13 00:33:28 +03:00
|
|
|
|
2009-07-10 21:56:32 +04:00
|
|
|
int
|
|
|
|
ddi_copyin(const void *from, void *to, size_t len, int flags)
|
|
|
|
{
|
|
|
|
/* Fake ioctl() issued by kernel, 'from' is a kernel address */
|
|
|
|
if (flags & FKIOCTL) {
|
|
|
|
memcpy(to, from, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copyin(from, to, len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ddi_copyin);
|
|
|
|
|
|
|
|
int
|
|
|
|
ddi_copyout(const void *from, void *to, size_t len, int flags)
|
|
|
|
{
|
|
|
|
/* Fake ioctl() issued by kernel, 'from' is a kernel address */
|
|
|
|
if (flags & FKIOCTL) {
|
|
|
|
memcpy(to, from, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copyout(from, to, len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ddi_copyout);
|
|
|
|
|
2009-09-19 03:09:47 +04:00
|
|
|
#ifndef HAVE_PUT_TASK_STRUCT
|
|
|
|
/*
|
|
|
|
* This is only a stub function which should never be used. The SPL should
|
|
|
|
* never be putting away the last reference on a task structure so this will
|
|
|
|
* not be called. However, we still need to define it so the module does not
|
|
|
|
* have undefined symbol at load time. That all said if this impossible
|
|
|
|
* thing does somehow happen SBUG() immediately so we know about it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
__put_task_struct(struct task_struct *t)
|
|
|
|
{
|
|
|
|
SBUG();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__put_task_struct);
|
|
|
|
#endif /* HAVE_PUT_TASK_STRUCT */
|
|
|
|
|
2008-06-04 01:20:18 +04:00
|
|
|
struct new_utsname *__utsname(void)
|
|
|
|
{
|
2008-08-12 02:13:47 +04:00
|
|
|
#ifdef HAVE_INIT_UTSNAME
|
2008-06-04 01:20:18 +04:00
|
|
|
return init_utsname();
|
2008-08-12 02:13:47 +04:00
|
|
|
#else
|
|
|
|
return &system_utsname;
|
|
|
|
#endif
|
2008-06-04 01:20:18 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__utsname);
|
|
|
|
|
2008-04-01 00:42:36 +04:00
|
|
|
static int
|
2008-04-19 03:39:58 +04:00
|
|
|
set_hostid(void)
|
2008-04-01 00:42:36 +04:00
|
|
|
{
|
2008-04-12 08:27:59 +04:00
|
|
|
char sh_path[] = "/bin/sh";
|
|
|
|
char *argv[] = { sh_path,
|
|
|
|
"-c",
|
2008-06-02 21:28:49 +04:00
|
|
|
"/usr/bin/hostid >/proc/sys/kernel/spl/hostid",
|
2008-04-12 08:27:59 +04:00
|
|
|
NULL };
|
|
|
|
char *envp[] = { "HOME=/",
|
|
|
|
"TERM=linux",
|
|
|
|
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
|
|
|
|
NULL };
|
2009-05-20 21:08:37 +04:00
|
|
|
int rc;
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
/* Doing address resolution in the kernel is tricky and just
|
2008-04-21 21:29:47 +04:00
|
|
|
* not a good idea in general. So to set the proper 'hw_serial'
|
2008-04-19 03:39:58 +04:00
|
|
|
* use the usermodehelper support to ask '/bin/sh' to run
|
|
|
|
* '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
|
2009-05-20 21:08:37 +04:00
|
|
|
* for us to use. It's a horrific solution but it will do for now.
|
2008-04-19 03:39:58 +04:00
|
|
|
*/
|
2009-05-20 21:08:37 +04:00
|
|
|
rc = call_usermodehelper(sh_path, argv, envp, 1);
|
|
|
|
if (rc)
|
|
|
|
printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
|
|
|
|
argv[0], argv[1], argv[2], rc);
|
|
|
|
|
|
|
|
return rc;
|
2008-04-19 03:39:58 +04:00
|
|
|
}
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2009-02-19 22:26:17 +03:00
|
|
|
uint32_t
|
|
|
|
zone_get_hostid(void *zone)
|
|
|
|
{
|
|
|
|
unsigned long hostid;
|
|
|
|
|
|
|
|
/* Only the global zone is supported */
|
|
|
|
ASSERT(zone == NULL);
|
|
|
|
|
|
|
|
if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
|
|
|
|
return HW_INVALID_HOSTID;
|
|
|
|
|
|
|
|
return (uint32_t)hostid;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zone_get_hostid);
|
|
|
|
|
2009-05-20 21:08:37 +04:00
|
|
|
#ifndef HAVE_KALLSYMS_LOOKUP_NAME
|
2009-02-26 00:20:40 +03:00
|
|
|
/*
|
|
|
|
* Because kallsyms_lookup_name() is no longer exported in the
|
|
|
|
* mainline kernel we are forced to resort to somewhat drastic
|
|
|
|
* measures. This function replaces the functionality by performing
|
|
|
|
* an upcall to user space where /proc/kallsyms is consulted for
|
|
|
|
* the requested address.
|
|
|
|
*/
|
|
|
|
#define GET_KALLSYMS_ADDR_CMD \
|
|
|
|
"awk '{ if ( $3 == \"kallsyms_lookup_name\") { print $1 } }' " \
|
|
|
|
"/proc/kallsyms >/proc/sys/kernel/spl/kallsyms_lookup_name"
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_kallsyms_lookup_name(void)
|
|
|
|
{
|
|
|
|
char sh_path[] = "/bin/sh";
|
|
|
|
char *argv[] = { sh_path,
|
|
|
|
"-c",
|
|
|
|
GET_KALLSYMS_ADDR_CMD,
|
|
|
|
NULL };
|
|
|
|
char *envp[] = { "HOME=/",
|
|
|
|
"TERM=linux",
|
|
|
|
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
|
|
|
|
NULL };
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = call_usermodehelper(sh_path, argv, envp, 1);
|
|
|
|
if (rc)
|
2009-05-20 21:08:37 +04:00
|
|
|
printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
|
|
|
|
argv[0], argv[1], argv[2], rc);
|
2009-02-26 00:20:40 +03:00
|
|
|
|
2009-05-20 21:08:37 +04:00
|
|
|
return rc;
|
2009-02-26 00:20:40 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-02 03:06:15 +04:00
|
|
|
static int
|
|
|
|
__init spl_init(void)
|
2008-04-19 03:39:58 +04:00
|
|
|
{
|
|
|
|
int rc = 0;
|
2008-04-12 08:27:59 +04:00
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
if ((rc = debug_init()))
|
2008-04-23 02:22:02 +04:00
|
|
|
return rc;
|
2008-04-12 08:27:59 +04:00
|
|
|
|
2008-06-14 03:41:06 +04:00
|
|
|
if ((rc = spl_kmem_init()))
|
2009-09-26 01:14:35 +04:00
|
|
|
GOTO(out1, rc);
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
if ((rc = spl_mutex_init()))
|
2009-09-26 01:14:35 +04:00
|
|
|
GOTO(out2, rc);
|
2008-05-06 00:18:49 +04:00
|
|
|
|
2009-09-26 01:14:35 +04:00
|
|
|
if ((rc = spl_rw_init()))
|
2008-05-06 00:18:49 +04:00
|
|
|
GOTO(out3, rc);
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2009-09-26 01:14:35 +04:00
|
|
|
if ((rc = spl_taskq_init()))
|
2008-05-06 00:18:49 +04:00
|
|
|
GOTO(out4, rc);
|
2008-03-14 03:04:01 +03:00
|
|
|
|
2009-09-26 01:14:35 +04:00
|
|
|
if ((rc = vn_init()))
|
2008-05-09 03:21:47 +04:00
|
|
|
GOTO(out5, rc);
|
|
|
|
|
2009-09-26 01:14:35 +04:00
|
|
|
if ((rc = proc_init()))
|
2009-01-06 02:08:03 +03:00
|
|
|
GOTO(out6, rc);
|
|
|
|
|
2009-09-26 01:14:35 +04:00
|
|
|
if ((rc = kstat_init()))
|
|
|
|
GOTO(out7, rc);
|
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
if ((rc = set_hostid()))
|
2009-09-26 01:14:35 +04:00
|
|
|
GOTO(out8, rc = -EADDRNOTAVAIL);
|
2008-04-12 08:27:59 +04:00
|
|
|
|
2009-05-20 21:08:37 +04:00
|
|
|
#ifndef HAVE_KALLSYMS_LOOKUP_NAME
|
2009-02-26 00:20:40 +03:00
|
|
|
if ((rc = set_kallsyms_lookup_name()))
|
2009-09-26 01:14:35 +04:00
|
|
|
GOTO(out8, rc = -EADDRNOTAVAIL);
|
2009-05-20 21:08:37 +04:00
|
|
|
#endif /* HAVE_KALLSYMS_LOOKUP_NAME */
|
|
|
|
|
|
|
|
if ((rc = spl_kmem_init_kallsyms_lookup()))
|
2009-09-26 01:14:35 +04:00
|
|
|
GOTO(out8, rc);
|
2009-02-26 00:20:40 +03:00
|
|
|
|
2009-03-18 00:55:59 +03:00
|
|
|
printk("SPL: Loaded Solaris Porting Layer v%s\n", SPL_META_VERSION);
|
2008-04-19 03:39:58 +04:00
|
|
|
RETURN(rc);
|
2009-09-26 01:14:35 +04:00
|
|
|
out8:
|
2008-05-09 03:21:47 +04:00
|
|
|
kstat_fini();
|
2009-09-26 01:14:35 +04:00
|
|
|
out7:
|
2008-04-19 03:39:58 +04:00
|
|
|
proc_fini();
|
2009-09-26 01:14:35 +04:00
|
|
|
out6:
|
2008-04-19 03:39:58 +04:00
|
|
|
vn_fini();
|
2009-09-26 01:14:35 +04:00
|
|
|
out5:
|
2009-01-06 02:08:03 +03:00
|
|
|
spl_taskq_fini();
|
2009-09-26 01:14:35 +04:00
|
|
|
out4:
|
|
|
|
spl_rw_fini();
|
2008-05-06 00:18:49 +04:00
|
|
|
out3:
|
|
|
|
spl_mutex_fini();
|
2008-04-01 00:42:36 +04:00
|
|
|
out2:
|
2008-06-14 03:41:06 +04:00
|
|
|
spl_kmem_fini();
|
2009-09-26 01:14:35 +04:00
|
|
|
out1:
|
2008-04-19 03:39:58 +04:00
|
|
|
debug_fini();
|
2008-04-01 00:42:36 +04:00
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
printk("SPL: Failed to Load Solaris Porting Layer v%s, "
|
2009-03-18 00:55:59 +03:00
|
|
|
"rc = %d\n", SPL_META_VERSION, rc);
|
2008-04-23 02:22:02 +04:00
|
|
|
return rc;
|
2008-02-28 00:56:51 +03:00
|
|
|
}
|
|
|
|
|
2009-10-02 03:06:15 +04:00
|
|
|
static void
|
|
|
|
spl_fini(void)
|
2008-02-28 00:56:51 +03:00
|
|
|
{
|
2008-04-19 03:39:58 +04:00
|
|
|
ENTRY;
|
|
|
|
|
2009-03-18 00:55:59 +03:00
|
|
|
printk("SPL: Unloaded Solaris Porting Layer v%s\n", SPL_META_VERSION);
|
2008-05-09 03:21:47 +04:00
|
|
|
kstat_fini();
|
2008-04-19 03:39:58 +04:00
|
|
|
proc_fini();
|
2008-03-14 03:04:01 +03:00
|
|
|
vn_fini();
|
2009-01-06 02:08:03 +03:00
|
|
|
spl_taskq_fini();
|
2009-09-26 01:14:35 +04:00
|
|
|
spl_rw_fini();
|
2008-06-14 03:41:06 +04:00
|
|
|
spl_mutex_fini();
|
|
|
|
spl_kmem_fini();
|
2008-04-19 03:39:58 +04:00
|
|
|
debug_fini();
|
2008-02-28 00:56:51 +03:00
|
|
|
}
|
|
|
|
|
2009-10-02 03:06:15 +04:00
|
|
|
/* Called when a dependent module is loaded */
|
|
|
|
void
|
|
|
|
spl_setup(void)
|
|
|
|
{
|
2010-04-22 23:48:40 +04:00
|
|
|
int rc;
|
|
|
|
|
2009-10-02 03:06:15 +04:00
|
|
|
/*
|
|
|
|
* At module load time the pwd is set to '/' on a Solaris system.
|
|
|
|
* On a Linux system will be set to whatever directory the caller
|
|
|
|
* was in when executing insmod/modprobe.
|
|
|
|
*/
|
2010-04-22 23:48:40 +04:00
|
|
|
rc = vn_set_pwd("/");
|
|
|
|
if (rc)
|
|
|
|
printk("SPL: Warning unable to set pwd to '/': %d\n", rc);
|
2009-10-02 03:06:15 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(spl_setup);
|
|
|
|
|
|
|
|
/* Called when a dependent module is unloaded */
|
|
|
|
void
|
|
|
|
spl_cleanup(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(spl_cleanup);
|
|
|
|
|
2008-02-28 00:56:51 +03:00
|
|
|
module_init(spl_init);
|
|
|
|
module_exit(spl_fini);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Lawrence Livermore National Labs");
|
|
|
|
MODULE_DESCRIPTION("Solaris Porting Layer");
|
|
|
|
MODULE_LICENSE("GPL");
|