2008-03-04 18:22:31 +00:00
|
|
|
#include <sys/sysmacros.h>
|
2008-03-14 00:04:01 +00:00
|
|
|
#include <sys/vmsystm.h>
|
|
|
|
#include <sys/vnode.h>
|
2008-03-14 20:56:26 +00:00
|
|
|
#include <sys/kmem.h>
|
2008-03-31 20:42:36 +00:00
|
|
|
#include <sys/debug.h>
|
2008-04-18 23:39:58 +00:00
|
|
|
#include <sys/proc.h>
|
2008-04-12 04:27:59 +00:00
|
|
|
#include <linux/kmod.h>
|
2008-02-27 21:56:51 +00:00
|
|
|
#include "config.h"
|
2008-02-27 19:09:51 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
#ifdef DEBUG_SUBSYSTEM
|
|
|
|
#undef DEBUG_SUBSYSTEM
|
|
|
|
#endif
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
#define DEBUG_SUBSYSTEM S_GENERIC
|
2008-04-12 04:27:59 +00:00
|
|
|
|
2008-04-21 17:29:47 +00:00
|
|
|
long spl_hostid = 0;
|
2008-04-12 04:27:59 +00:00
|
|
|
EXPORT_SYMBOL(spl_hostid);
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-04-21 17:29:47 +00:00
|
|
|
char hw_serial[11] = "<none>";
|
|
|
|
EXPORT_SYMBOL(hw_serial);
|
2008-02-27 19:09:51 +00:00
|
|
|
|
|
|
|
int p0 = 0;
|
|
|
|
EXPORT_SYMBOL(p0);
|
2008-02-27 21:56:51 +00:00
|
|
|
|
2008-03-14 00:04:01 +00:00
|
|
|
vmem_t *zio_alloc_arena = NULL;
|
|
|
|
EXPORT_SYMBOL(zio_alloc_arena);
|
|
|
|
|
2008-03-06 23:12:55 +00:00
|
|
|
int
|
|
|
|
highbit(unsigned long i)
|
|
|
|
{
|
|
|
|
register int h = 1;
|
2008-04-18 23:39:58 +00:00
|
|
|
ENTRY;
|
2008-03-06 23:12:55 +00:00
|
|
|
|
|
|
|
if (i == 0)
|
2008-04-18 23:39:58 +00:00
|
|
|
RETURN(0);
|
2008-03-06 23:12:55 +00: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-18 23:39:58 +00:00
|
|
|
RETURN(h);
|
2008-03-06 23:12:55 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(highbit);
|
|
|
|
|
2008-03-12 21:33:28 +00:00
|
|
|
int
|
|
|
|
ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
return (*result = simple_strtoul(str, &end, base));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ddi_strtoul);
|
|
|
|
|
2008-03-31 20:42:36 +00:00
|
|
|
static int
|
2008-04-18 23:39:58 +00:00
|
|
|
set_hostid(void)
|
2008-03-31 20:42:36 +00:00
|
|
|
{
|
2008-04-12 04:27:59 +00:00
|
|
|
char sh_path[] = "/bin/sh";
|
|
|
|
char *argv[] = { sh_path,
|
|
|
|
"-c",
|
2008-04-18 23:39:58 +00:00
|
|
|
"/usr/bin/hostid >/proc/sys/spl/hostid",
|
2008-04-12 04:27:59 +00:00
|
|
|
NULL };
|
|
|
|
char *envp[] = { "HOME=/",
|
|
|
|
"TERM=linux",
|
|
|
|
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
|
|
|
|
NULL };
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
/* Doing address resolution in the kernel is tricky and just
|
2008-04-21 17:29:47 +00:00
|
|
|
* not a good idea in general. So to set the proper 'hw_serial'
|
2008-04-18 23:39:58 +00:00
|
|
|
* use the usermodehelper support to ask '/bin/sh' to run
|
|
|
|
* '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
|
|
|
|
* for us to use. It's a horific solution but it will do for now.
|
|
|
|
*/
|
|
|
|
return call_usermodehelper(sh_path, argv, envp, 1);
|
|
|
|
}
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
static int __init spl_init(void)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
ENTRY;
|
2008-04-12 04:27:59 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
if ((rc = debug_init()))
|
|
|
|
RETURN(rc);
|
2008-04-12 04:27:59 +00:00
|
|
|
|
2008-03-31 20:42:36 +00:00
|
|
|
if ((rc = kmem_init()))
|
2008-04-18 23:39:58 +00:00
|
|
|
GOTO(out , rc);
|
2008-03-31 20:42:36 +00:00
|
|
|
|
|
|
|
if ((rc = vn_init()))
|
2008-04-18 23:39:58 +00:00
|
|
|
GOTO(out2, rc);
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
if ((rc = proc_init()))
|
|
|
|
GOTO(out3, rc);
|
2008-03-14 00:04:01 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
if ((rc = set_hostid()))
|
|
|
|
GOTO(out4, rc = -EADDRNOTAVAIL);
|
2008-04-12 04:27:59 +00:00
|
|
|
|
2008-04-21 17:29:47 +00:00
|
|
|
printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION);
|
2008-04-18 23:39:58 +00:00
|
|
|
RETURN(rc);
|
2008-04-12 04:27:59 +00:00
|
|
|
out4:
|
2008-04-18 23:39:58 +00:00
|
|
|
proc_fini();
|
2008-04-12 04:27:59 +00:00
|
|
|
out3:
|
2008-04-18 23:39:58 +00:00
|
|
|
vn_fini();
|
2008-03-31 20:42:36 +00:00
|
|
|
out2:
|
2008-04-18 23:39:58 +00:00
|
|
|
kmem_fini();
|
2008-03-31 20:42:36 +00:00
|
|
|
out:
|
2008-04-18 23:39:58 +00:00
|
|
|
debug_fini();
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
printk("SPL: Failed to Load Solaris Porting Layer v%s, "
|
|
|
|
"rc = %d\n", VERSION, rc);
|
|
|
|
RETURN(rc);
|
2008-02-27 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void spl_fini(void)
|
|
|
|
{
|
2008-04-18 23:39:58 +00:00
|
|
|
ENTRY;
|
|
|
|
|
2008-04-21 17:29:47 +00:00
|
|
|
printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION);
|
2008-04-18 23:39:58 +00:00
|
|
|
proc_fini();
|
2008-03-14 00:04:01 +00:00
|
|
|
vn_fini();
|
2008-03-18 23:20:30 +00:00
|
|
|
kmem_fini();
|
2008-04-18 23:39:58 +00:00
|
|
|
debug_fini();
|
2008-03-14 20:56:26 +00:00
|
|
|
|
2008-04-18 23:39:58 +00:00
|
|
|
EXIT;
|
2008-02-27 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(spl_init);
|
|
|
|
module_exit(spl_fini);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Lawrence Livermore National Labs");
|
|
|
|
MODULE_DESCRIPTION("Solaris Porting Layer");
|
|
|
|
MODULE_LICENSE("GPL");
|