]> git.proxmox.com Git - mirror_spl.git/blame - modules/spl/spl-generic.c
Prep for for 0.3.0 tag, this is the tag which was used for all
[mirror_spl.git] / modules / spl / spl-generic.c
CommitLineData
14c5326c 1#include <sys/sysmacros.h>
af828292 2#include <sys/vmsystm.h>
3#include <sys/vnode.h>
c19c06f3 4#include <sys/kmem.h>
9ab1ac14 5#include <sys/mutex.h>
8d0f1ee9 6#include <sys/debug.h>
57d1b188 7#include <sys/proc.h>
04a479f7 8#include <sys/kstat.h>
f23e92fa 9#include <linux/kmod.h>
70eadc19 10#include "config.h"
f1b59d26 11
57d1b188 12#ifdef DEBUG_SUBSYSTEM
13#undef DEBUG_SUBSYSTEM
14#endif
8d0f1ee9 15
57d1b188 16#define DEBUG_SUBSYSTEM S_GENERIC
f23e92fa 17
3561541c 18char spl_version[16] = "SPL v" VERSION;
19
937879f1 20long spl_hostid = 0;
f23e92fa 21EXPORT_SYMBOL(spl_hostid);
8d0f1ee9 22
937879f1 23char hw_serial[11] = "<none>";
24EXPORT_SYMBOL(hw_serial);
f1b59d26 25
26int p0 = 0;
27EXPORT_SYMBOL(p0);
70eadc19 28
af828292 29vmem_t *zio_alloc_arena = NULL;
30EXPORT_SYMBOL(zio_alloc_arena);
31
77b1fe8f 32int
33highbit(unsigned long i)
34{
35 register int h = 1;
57d1b188 36 ENTRY;
77b1fe8f 37
38 if (i == 0)
57d1b188 39 RETURN(0);
77b1fe8f 40#if BITS_PER_LONG == 64
41 if (i & 0xffffffff00000000ul) {
42 h += 32; i >>= 32;
43 }
44#endif
45 if (i & 0xffff0000) {
46 h += 16; i >>= 16;
47 }
48 if (i & 0xff00) {
49 h += 8; i >>= 8;
50 }
51 if (i & 0xf0) {
52 h += 4; i >>= 4;
53 }
54 if (i & 0xc) {
55 h += 2; i >>= 2;
56 }
57 if (i & 0x2) {
58 h += 1;
59 }
57d1b188 60 RETURN(h);
77b1fe8f 61}
62EXPORT_SYMBOL(highbit);
63
2f5d55aa 64int
65ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result)
66{
67 char *end;
68 return (*result = simple_strtoul(str, &end, base));
69}
70EXPORT_SYMBOL(ddi_strtoul);
71
8d0f1ee9 72static int
57d1b188 73set_hostid(void)
8d0f1ee9 74{
f23e92fa 75 char sh_path[] = "/bin/sh";
76 char *argv[] = { sh_path,
77 "-c",
57d1b188 78 "/usr/bin/hostid >/proc/sys/spl/hostid",
f23e92fa 79 NULL };
80 char *envp[] = { "HOME=/",
81 "TERM=linux",
82 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
83 NULL };
8d0f1ee9 84
57d1b188 85 /* Doing address resolution in the kernel is tricky and just
937879f1 86 * not a good idea in general. So to set the proper 'hw_serial'
57d1b188 87 * use the usermodehelper support to ask '/bin/sh' to run
88 * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
89 * for us to use. It's a horific solution but it will do for now.
90 */
91 return call_usermodehelper(sh_path, argv, envp, 1);
92}
8d0f1ee9 93
57d1b188 94static int __init spl_init(void)
95{
96 int rc = 0;
f23e92fa 97
57d1b188 98 if ((rc = debug_init()))
18c9eadf 99 return rc;
f23e92fa 100
8d0f1ee9 101 if ((rc = kmem_init()))
57d1b188 102 GOTO(out , rc);
8d0f1ee9 103
9ab1ac14 104 if ((rc = spl_mutex_init()))
105 GOTO(out2 , rc);
106
8d0f1ee9 107 if ((rc = vn_init()))
9ab1ac14 108 GOTO(out3, rc);
8d0f1ee9 109
57d1b188 110 if ((rc = proc_init()))
9ab1ac14 111 GOTO(out4, rc);
af828292 112
04a479f7 113 if ((rc = kstat_init()))
114 GOTO(out5, rc);
115
57d1b188 116 if ((rc = set_hostid()))
04a479f7 117 GOTO(out6, rc = -EADDRNOTAVAIL);
f23e92fa 118
937879f1 119 printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION);
57d1b188 120 RETURN(rc);
04a479f7 121out6:
122 kstat_fini();
9ab1ac14 123out5:
57d1b188 124 proc_fini();
9ab1ac14 125out4:
57d1b188 126 vn_fini();
9ab1ac14 127out3:
128 spl_mutex_fini();
8d0f1ee9 129out2:
57d1b188 130 kmem_fini();
8d0f1ee9 131out:
57d1b188 132 debug_fini();
8d0f1ee9 133
57d1b188 134 printk("SPL: Failed to Load Solaris Porting Layer v%s, "
135 "rc = %d\n", VERSION, rc);
18c9eadf 136 return rc;
70eadc19 137}
138
139static void spl_fini(void)
140{
57d1b188 141 ENTRY;
142
937879f1 143 printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION);
04a479f7 144 kstat_fini();
57d1b188 145 proc_fini();
af828292 146 vn_fini();
e4f1d29f 147 kmem_fini();
57d1b188 148 debug_fini();
70eadc19 149}
150
151module_init(spl_init);
152module_exit(spl_fini);
153
154MODULE_AUTHOR("Lawrence Livermore National Labs");
155MODULE_DESCRIPTION("Solaris Porting Layer");
156MODULE_LICENSE("GPL");