]> git.proxmox.com Git - mirror_spl-debian.git/blame - modules/spl/spl-generic.c
Add missing stub headers
[mirror_spl-debian.git] / modules / spl / spl-generic.c
CommitLineData
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>
e9cb2b4f 32#include <sys/taskq.h>
8d0f1ee9 33#include <sys/debug.h>
57d1b188 34#include <sys/proc.h>
04a479f7 35#include <sys/kstat.h>
691d2bd7 36#include <sys/utsname.h>
f23e92fa 37#include <linux/kmod.h>
f1b59d26 38
57d1b188 39#ifdef DEBUG_SUBSYSTEM
40#undef DEBUG_SUBSYSTEM
41#endif
8d0f1ee9 42
57d1b188 43#define DEBUG_SUBSYSTEM S_GENERIC
f23e92fa 44
3561541c 45char spl_version[16] = "SPL v" VERSION;
46
937879f1 47long spl_hostid = 0;
f23e92fa 48EXPORT_SYMBOL(spl_hostid);
8d0f1ee9 49
937879f1 50char hw_serial[11] = "<none>";
51EXPORT_SYMBOL(hw_serial);
f1b59d26 52
53int p0 = 0;
54EXPORT_SYMBOL(p0);
70eadc19 55
af828292 56vmem_t *zio_alloc_arena = NULL;
57EXPORT_SYMBOL(zio_alloc_arena);
58
77b1fe8f 59int
60highbit(unsigned long i)
61{
62 register int h = 1;
3d061e9d 63 ENTRY;
77b1fe8f 64
65 if (i == 0)
57d1b188 66 RETURN(0);
77b1fe8f 67#if BITS_PER_LONG == 64
68 if (i & 0xffffffff00000000ul) {
69 h += 32; i >>= 32;
70 }
71#endif
72 if (i & 0xffff0000) {
73 h += 16; i >>= 16;
74 }
75 if (i & 0xff00) {
76 h += 8; i >>= 8;
77 }
78 if (i & 0xf0) {
79 h += 4; i >>= 4;
80 }
81 if (i & 0xc) {
82 h += 2; i >>= 2;
83 }
84 if (i & 0x2) {
85 h += 1;
86 }
57d1b188 87 RETURN(h);
77b1fe8f 88}
89EXPORT_SYMBOL(highbit);
90
b61a6e8b 91/*
550f1705 92 * Implementation of 64 bit division for 32-bit machines.
b61a6e8b 93 */
550f1705 94#if BITS_PER_LONG == 32
95uint64_t __udivdi3(uint64_t dividend, uint64_t divisor)
b61a6e8b 96{
550f1705 97#ifdef HAVE_DIV64_64
98 return div64_64(dividend, divisor);
99#else
100 /* Taken from a 2.6.24 kernel. */
b61a6e8b 101 uint32_t high, d;
102
103 high = divisor >> 32;
104 if (high) {
105 unsigned int shift = fls(high);
106
107 d = divisor >> shift;
108 dividend >>= shift;
109 } else
110 d = divisor;
111
112 do_div(dividend, d);
113
114 return dividend;
550f1705 115#endif
116}
117EXPORT_SYMBOL(__udivdi3);
118
119/*
120 * Implementation of 64 bit modulo for 32-bit machines.
121 */
122uint64_t __umoddi3(uint64_t dividend, uint64_t divisor)
123{
124 return dividend - divisor * (dividend / divisor);
b61a6e8b 125}
550f1705 126EXPORT_SYMBOL(__umoddi3);
127#endif
b61a6e8b 128
2ee63a54
BB
129int ddi_strtoul(const char *, char **, int, unsigned long *);
130int ddi_strtol(const char *, char **, int, long *);
131int ddi_strtoull(const char *, char **, int, unsigned long long *);
132int ddi_strtoll(const char *, char **, int, long long *);
133
134#define define_ddi_strtoux(type, valtype) \
135int ddi_strtou##type(const char *str, char **endptr, \
136 int base, valtype *result) \
137{ \
138 valtype val; \
139 size_t len; \
140 \
141 len = strlen(str); \
142 if (len == 0) \
143 return -EINVAL; \
144 \
145 val = simple_strtoul(str, endptr, (unsigned int)base); \
146 if ((**endptr == '\0') || \
147 ((len == (size_t)(*endptr-str) + 1) && (**endptr == '\n'))) {\
148 *result = val; \
149 return 0; \
150 } \
151 \
152 return -EINVAL; \
153} \
154
155#define define_ddi_strtox(type, valtype) \
156int ddi_strto##type(const char *str, char **endptr, \
157 int base, valtype *result) \
158{ \
159 int ret; \
160 \
161 if (*str == '-') { \
162 ret = ddi_strtou##type(str+1, endptr, \
163 (unsigned int)base, result); \
164 if (!ret) \
165 *result = -(*result); \
166 } else { \
167 ret = ddi_strtou##type(str, endptr, \
168 (unsigned int)base, result); \
169 } \
170 \
171 return ret; \
172} \
173
174define_ddi_strtoux(l, unsigned long)
175define_ddi_strtox(l, long)
176define_ddi_strtoux(ll, unsigned long long)
177define_ddi_strtox(ll, long long)
178
2f5d55aa 179EXPORT_SYMBOL(ddi_strtoul);
2ee63a54
BB
180EXPORT_SYMBOL(ddi_strtol);
181EXPORT_SYMBOL(ddi_strtoll);
182EXPORT_SYMBOL(ddi_strtoull);
2f5d55aa 183
691d2bd7 184struct new_utsname *__utsname(void)
185{
3d061e9d 186#ifdef HAVE_INIT_UTSNAME
691d2bd7 187 return init_utsname();
3d061e9d 188#else
189 return &system_utsname;
190#endif
691d2bd7 191}
192EXPORT_SYMBOL(__utsname);
193
8d0f1ee9 194static int
57d1b188 195set_hostid(void)
8d0f1ee9 196{
f23e92fa 197 char sh_path[] = "/bin/sh";
198 char *argv[] = { sh_path,
199 "-c",
57d86234 200 "/usr/bin/hostid >/proc/sys/kernel/spl/hostid",
f23e92fa 201 NULL };
202 char *envp[] = { "HOME=/",
203 "TERM=linux",
204 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
205 NULL };
8d0f1ee9 206
57d1b188 207 /* Doing address resolution in the kernel is tricky and just
937879f1 208 * not a good idea in general. So to set the proper 'hw_serial'
57d1b188 209 * use the usermodehelper support to ask '/bin/sh' to run
210 * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
211 * for us to use. It's a horific solution but it will do for now.
212 */
213 return call_usermodehelper(sh_path, argv, envp, 1);
214}
8d0f1ee9 215
57d1b188 216static int __init spl_init(void)
217{
218 int rc = 0;
f23e92fa 219
57d1b188 220 if ((rc = debug_init()))
18c9eadf 221 return rc;
f23e92fa 222
2fb9b26a 223 if ((rc = spl_kmem_init()))
57d1b188 224 GOTO(out , rc);
8d0f1ee9 225
9ab1ac14 226 if ((rc = spl_mutex_init()))
227 GOTO(out2 , rc);
228
e9cb2b4f 229 if ((rc = spl_taskq_init()))
9ab1ac14 230 GOTO(out3, rc);
8d0f1ee9 231
e9cb2b4f 232 if ((rc = vn_init()))
9ab1ac14 233 GOTO(out4, rc);
af828292 234
e9cb2b4f 235 if ((rc = proc_init()))
04a479f7 236 GOTO(out5, rc);
237
e9cb2b4f
BB
238 if ((rc = kstat_init()))
239 GOTO(out6, rc);
240
57d1b188 241 if ((rc = set_hostid()))
e9cb2b4f 242 GOTO(out7, rc = -EADDRNOTAVAIL);
f23e92fa 243
937879f1 244 printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION);
57d1b188 245 RETURN(rc);
e9cb2b4f 246out7:
04a479f7 247 kstat_fini();
e9cb2b4f 248out6:
57d1b188 249 proc_fini();
e9cb2b4f 250out5:
57d1b188 251 vn_fini();
e9cb2b4f
BB
252out4:
253 spl_taskq_fini();
9ab1ac14 254out3:
255 spl_mutex_fini();
8d0f1ee9 256out2:
2fb9b26a 257 spl_kmem_fini();
8d0f1ee9 258out:
57d1b188 259 debug_fini();
8d0f1ee9 260
57d1b188 261 printk("SPL: Failed to Load Solaris Porting Layer v%s, "
262 "rc = %d\n", VERSION, rc);
18c9eadf 263 return rc;
70eadc19 264}
265
266static void spl_fini(void)
267{
57d1b188 268 ENTRY;
269
937879f1 270 printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION);
04a479f7 271 kstat_fini();
57d1b188 272 proc_fini();
af828292 273 vn_fini();
e9cb2b4f 274 spl_taskq_fini();
2fb9b26a 275 spl_mutex_fini();
276 spl_kmem_fini();
57d1b188 277 debug_fini();
70eadc19 278}
279
280module_init(spl_init);
281module_exit(spl_fini);
282
283MODULE_AUTHOR("Lawrence Livermore National Labs");
284MODULE_DESCRIPTION("Solaris Porting Layer");
285MODULE_LICENSE("GPL");