]>
Commit | Line | Data |
---|---|---|
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 | 18 | char spl_version[16] = "SPL v" VERSION; |
19 | ||
937879f1 | 20 | long spl_hostid = 0; |
f23e92fa | 21 | EXPORT_SYMBOL(spl_hostid); |
8d0f1ee9 | 22 | |
937879f1 | 23 | char hw_serial[11] = "<none>"; |
24 | EXPORT_SYMBOL(hw_serial); | |
f1b59d26 | 25 | |
26 | int p0 = 0; | |
27 | EXPORT_SYMBOL(p0); | |
70eadc19 | 28 | |
af828292 | 29 | vmem_t *zio_alloc_arena = NULL; |
30 | EXPORT_SYMBOL(zio_alloc_arena); | |
31 | ||
77b1fe8f | 32 | int |
33 | highbit(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 | } |
62 | EXPORT_SYMBOL(highbit); | |
63 | ||
2f5d55aa | 64 | int |
65 | ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result) | |
66 | { | |
67 | char *end; | |
68 | return (*result = simple_strtoul(str, &end, base)); | |
69 | } | |
70 | EXPORT_SYMBOL(ddi_strtoul); | |
71 | ||
8d0f1ee9 | 72 | static int |
57d1b188 | 73 | set_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 | 94 | static 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 | 121 | out6: |
122 | kstat_fini(); | |
9ab1ac14 | 123 | out5: |
57d1b188 | 124 | proc_fini(); |
9ab1ac14 | 125 | out4: |
57d1b188 | 126 | vn_fini(); |
9ab1ac14 | 127 | out3: |
128 | spl_mutex_fini(); | |
8d0f1ee9 | 129 | out2: |
57d1b188 | 130 | kmem_fini(); |
8d0f1ee9 | 131 | out: |
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 | ||
139 | static 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 | ||
151 | module_init(spl_init); | |
152 | module_exit(spl_fini); | |
153 | ||
154 | MODULE_AUTHOR("Lawrence Livermore National Labs"); | |
155 | MODULE_DESCRIPTION("Solaris Porting Layer"); | |
156 | MODULE_LICENSE("GPL"); |