]>
Commit | Line | Data |
---|---|---|
715f6251 | 1 | /* |
2 | * This file is part of the SPL: Solaris Porting Layer. | |
3 | * | |
4 | * Copyright (c) 2008 Lawrence Livermore National Security, LLC. | |
5 | * Produced at Lawrence Livermore National Laboratory | |
6 | * Written by: | |
7 | * Brian Behlendorf <behlendorf1@llnl.gov>, | |
8 | * Herb Wartens <wartens2@llnl.gov>, | |
9 | * Jim Garlick <garlick@llnl.gov> | |
10 | * UCRL-CODE-235197 | |
11 | * | |
12 | * This is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This is distributed in the hope that it will be useful, but WITHOUT | |
18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | * for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License along | |
23 | * with this program; if not, write to the Free Software Foundation, Inc., | |
24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
25 | */ | |
26 | ||
14c5326c | 27 | #include <sys/sysmacros.h> |
af828292 | 28 | #include <sys/vmsystm.h> |
29 | #include <sys/vnode.h> | |
c19c06f3 | 30 | #include <sys/kmem.h> |
9ab1ac14 | 31 | #include <sys/mutex.h> |
8d0f1ee9 | 32 | #include <sys/debug.h> |
57d1b188 | 33 | #include <sys/proc.h> |
04a479f7 | 34 | #include <sys/kstat.h> |
691d2bd7 | 35 | #include <sys/utsname.h> |
f23e92fa | 36 | #include <linux/kmod.h> |
f1b59d26 | 37 | |
57d1b188 | 38 | #ifdef DEBUG_SUBSYSTEM |
39 | #undef DEBUG_SUBSYSTEM | |
40 | #endif | |
8d0f1ee9 | 41 | |
57d1b188 | 42 | #define DEBUG_SUBSYSTEM S_GENERIC |
f23e92fa | 43 | |
3561541c | 44 | char spl_version[16] = "SPL v" VERSION; |
45 | ||
937879f1 | 46 | long spl_hostid = 0; |
f23e92fa | 47 | EXPORT_SYMBOL(spl_hostid); |
8d0f1ee9 | 48 | |
937879f1 | 49 | char hw_serial[11] = "<none>"; |
50 | EXPORT_SYMBOL(hw_serial); | |
f1b59d26 | 51 | |
52 | int p0 = 0; | |
53 | EXPORT_SYMBOL(p0); | |
70eadc19 | 54 | |
af828292 | 55 | vmem_t *zio_alloc_arena = NULL; |
56 | EXPORT_SYMBOL(zio_alloc_arena); | |
57 | ||
77b1fe8f | 58 | int |
59 | highbit(unsigned long i) | |
60 | { | |
61 | register int h = 1; | |
3d061e9d | 62 | ENTRY; |
77b1fe8f | 63 | |
64 | if (i == 0) | |
57d1b188 | 65 | RETURN(0); |
77b1fe8f | 66 | #if BITS_PER_LONG == 64 |
67 | if (i & 0xffffffff00000000ul) { | |
68 | h += 32; i >>= 32; | |
69 | } | |
70 | #endif | |
71 | if (i & 0xffff0000) { | |
72 | h += 16; i >>= 16; | |
73 | } | |
74 | if (i & 0xff00) { | |
75 | h += 8; i >>= 8; | |
76 | } | |
77 | if (i & 0xf0) { | |
78 | h += 4; i >>= 4; | |
79 | } | |
80 | if (i & 0xc) { | |
81 | h += 2; i >>= 2; | |
82 | } | |
83 | if (i & 0x2) { | |
84 | h += 1; | |
85 | } | |
57d1b188 | 86 | RETURN(h); |
77b1fe8f | 87 | } |
88 | EXPORT_SYMBOL(highbit); | |
89 | ||
b61a6e8b | 90 | /* |
91 | * Implementation of div64_64(), for kernels that don't have it. | |
92 | * | |
93 | * Taken from a 2.6.24 kernel. | |
94 | */ | |
95 | uint64_t spl_div64_64(uint64_t dividend, uint64_t divisor) | |
96 | { | |
97 | uint32_t high, d; | |
98 | ||
99 | high = divisor >> 32; | |
100 | if (high) { | |
101 | unsigned int shift = fls(high); | |
102 | ||
103 | d = divisor >> shift; | |
104 | dividend >>= shift; | |
105 | } else | |
106 | d = divisor; | |
107 | ||
108 | do_div(dividend, d); | |
109 | ||
110 | return dividend; | |
111 | } | |
112 | EXPORT_SYMBOL(spl_div64_64); | |
113 | ||
2f5d55aa | 114 | int |
115 | ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result) | |
116 | { | |
117 | char *end; | |
118 | return (*result = simple_strtoul(str, &end, base)); | |
119 | } | |
120 | EXPORT_SYMBOL(ddi_strtoul); | |
121 | ||
691d2bd7 | 122 | struct new_utsname *__utsname(void) |
123 | { | |
3d061e9d | 124 | #ifdef HAVE_INIT_UTSNAME |
691d2bd7 | 125 | return init_utsname(); |
3d061e9d | 126 | #else |
127 | return &system_utsname; | |
128 | #endif | |
691d2bd7 | 129 | } |
130 | EXPORT_SYMBOL(__utsname); | |
131 | ||
8d0f1ee9 | 132 | static int |
57d1b188 | 133 | set_hostid(void) |
8d0f1ee9 | 134 | { |
f23e92fa | 135 | char sh_path[] = "/bin/sh"; |
136 | char *argv[] = { sh_path, | |
137 | "-c", | |
57d86234 | 138 | "/usr/bin/hostid >/proc/sys/kernel/spl/hostid", |
f23e92fa | 139 | NULL }; |
140 | char *envp[] = { "HOME=/", | |
141 | "TERM=linux", | |
142 | "PATH=/sbin:/usr/sbin:/bin:/usr/bin", | |
143 | NULL }; | |
8d0f1ee9 | 144 | |
57d1b188 | 145 | /* Doing address resolution in the kernel is tricky and just |
937879f1 | 146 | * not a good idea in general. So to set the proper 'hw_serial' |
57d1b188 | 147 | * use the usermodehelper support to ask '/bin/sh' to run |
148 | * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid | |
149 | * for us to use. It's a horific solution but it will do for now. | |
150 | */ | |
151 | return call_usermodehelper(sh_path, argv, envp, 1); | |
152 | } | |
8d0f1ee9 | 153 | |
57d1b188 | 154 | static int __init spl_init(void) |
155 | { | |
156 | int rc = 0; | |
f23e92fa | 157 | |
57d1b188 | 158 | if ((rc = debug_init())) |
18c9eadf | 159 | return rc; |
f23e92fa | 160 | |
2fb9b26a | 161 | if ((rc = spl_kmem_init())) |
57d1b188 | 162 | GOTO(out , rc); |
8d0f1ee9 | 163 | |
9ab1ac14 | 164 | if ((rc = spl_mutex_init())) |
165 | GOTO(out2 , rc); | |
166 | ||
8d0f1ee9 | 167 | if ((rc = vn_init())) |
9ab1ac14 | 168 | GOTO(out3, rc); |
8d0f1ee9 | 169 | |
57d1b188 | 170 | if ((rc = proc_init())) |
9ab1ac14 | 171 | GOTO(out4, rc); |
af828292 | 172 | |
04a479f7 | 173 | if ((rc = kstat_init())) |
174 | GOTO(out5, rc); | |
175 | ||
57d1b188 | 176 | if ((rc = set_hostid())) |
04a479f7 | 177 | GOTO(out6, rc = -EADDRNOTAVAIL); |
f23e92fa | 178 | |
937879f1 | 179 | printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION); |
57d1b188 | 180 | RETURN(rc); |
04a479f7 | 181 | out6: |
182 | kstat_fini(); | |
9ab1ac14 | 183 | out5: |
57d1b188 | 184 | proc_fini(); |
9ab1ac14 | 185 | out4: |
57d1b188 | 186 | vn_fini(); |
9ab1ac14 | 187 | out3: |
188 | spl_mutex_fini(); | |
8d0f1ee9 | 189 | out2: |
2fb9b26a | 190 | spl_kmem_fini(); |
8d0f1ee9 | 191 | out: |
57d1b188 | 192 | debug_fini(); |
8d0f1ee9 | 193 | |
57d1b188 | 194 | printk("SPL: Failed to Load Solaris Porting Layer v%s, " |
195 | "rc = %d\n", VERSION, rc); | |
18c9eadf | 196 | return rc; |
70eadc19 | 197 | } |
198 | ||
199 | static void spl_fini(void) | |
200 | { | |
57d1b188 | 201 | ENTRY; |
202 | ||
937879f1 | 203 | printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION); |
04a479f7 | 204 | kstat_fini(); |
57d1b188 | 205 | proc_fini(); |
af828292 | 206 | vn_fini(); |
2fb9b26a | 207 | spl_mutex_fini(); |
208 | spl_kmem_fini(); | |
57d1b188 | 209 | debug_fini(); |
70eadc19 | 210 | } |
211 | ||
212 | module_init(spl_init); | |
213 | module_exit(spl_fini); | |
214 | ||
215 | MODULE_AUTHOR("Lawrence Livermore National Labs"); | |
216 | MODULE_DESCRIPTION("Solaris Porting Layer"); | |
217 | MODULE_LICENSE("GPL"); |