]>
git.proxmox.com Git - mirror_spl-debian.git/blob - module/spl/spl-generic.c
2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
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.
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
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.
27 #include <sys/sysmacros.h>
28 #include <sys/vmsystm.h>
29 #include <sys/vnode.h>
31 #include <sys/mutex.h>
32 #include <sys/taskq.h>
33 #include <sys/debug.h>
35 #include <sys/kstat.h>
36 #include <sys/utsname.h>
37 #include <linux/kmod.h>
39 #ifdef DEBUG_SUBSYSTEM
40 #undef DEBUG_SUBSYSTEM
43 #define DEBUG_SUBSYSTEM S_GENERIC
45 char spl_version
[16] = "SPL v" VERSION
;
48 EXPORT_SYMBOL(spl_hostid
);
50 char hw_serial
[11] = "<none>";
51 EXPORT_SYMBOL(hw_serial
);
56 vmem_t
*zio_alloc_arena
= NULL
;
57 EXPORT_SYMBOL(zio_alloc_arena
);
60 highbit(unsigned long i
)
67 #if BITS_PER_LONG == 64
68 if (i
& 0xffffffff00000000ul
) {
89 EXPORT_SYMBOL(highbit
);
92 * Implementation of 64 bit division for 32-bit machines.
94 #if BITS_PER_LONG == 32
95 uint64_t __udivdi3(uint64_t dividend
, uint64_t divisor
)
98 return div64_64(dividend
, divisor
);
100 /* Taken from a 2.6.24 kernel. */
103 high
= divisor
>> 32;
105 unsigned int shift
= fls(high
);
107 d
= divisor
>> shift
;
117 EXPORT_SYMBOL(__udivdi3
);
120 * Implementation of 64 bit modulo for 32-bit machines.
122 uint64_t __umoddi3(uint64_t dividend
, uint64_t divisor
)
124 return dividend
- divisor
* (dividend
/ divisor
);
126 EXPORT_SYMBOL(__umoddi3
);
129 /* NOTE: The strtoxx behavior is solely based on my reading of the Solaris
130 * ddi_strtol(9F) man page. I have not verified the behavior of these
131 * functions against their Solaris counterparts. It is possible that I
132 * may have misinterpretted the man page or the man page is incorrect.
134 int ddi_strtoul(const char *, char **, int, unsigned long *);
135 int ddi_strtol(const char *, char **, int, long *);
136 int ddi_strtoull(const char *, char **, int, unsigned long long *);
137 int ddi_strtoll(const char *, char **, int, long long *);
139 #define define_ddi_strtoux(type, valtype) \
140 int ddi_strtou##type(const char *str, char **endptr, \
141 int base, valtype *result) \
143 valtype last_value, value = 0; \
144 char *ptr = (char *)str; \
145 int flag = 1, digit; \
147 if (strlen(ptr) == 0) \
150 /* Auto-detect base based on prefix */ \
152 if (str[0] == '0') { \
153 if (tolower(str[1])=='x' && isxdigit(str[2])) { \
154 base = 16; /* hex */ \
156 } else if (str[1] >= '0' && str[1] < 8) { \
157 base = 8; /* octal */ \
163 base = 10; /* decimal */ \
169 digit = *ptr - '0'; \
170 else if (isalpha(*ptr)) \
171 digit = tolower(*ptr) - 'a' + 10; \
178 last_value = value; \
179 value = value * base + digit; \
180 if (last_value > value) /* Overflow */ \
191 *endptr = (char *)(flag ? ptr : str); \
196 #define define_ddi_strtox(type, valtype) \
197 int ddi_strto##type(const char *str, char **endptr, \
198 int base, valtype *result) \
203 rc = ddi_strtou##type(str + 1, endptr, base, result); \
205 if (*endptr == str + 1) \
206 *endptr = (char *)str; \
208 *result = -*result; \
211 rc = ddi_strtou##type(str, endptr, base, result); \
217 define_ddi_strtoux(l
, unsigned long)
218 define_ddi_strtox(l
, long)
219 define_ddi_strtoux(ll
, unsigned long long)
220 define_ddi_strtox(ll
, long long)
222 EXPORT_SYMBOL(ddi_strtoul
);
223 EXPORT_SYMBOL(ddi_strtol
);
224 EXPORT_SYMBOL(ddi_strtoll
);
225 EXPORT_SYMBOL(ddi_strtoull
);
227 struct new_utsname
*__utsname(void)
229 #ifdef HAVE_INIT_UTSNAME
230 return init_utsname();
232 return &system_utsname
;
235 EXPORT_SYMBOL(__utsname
);
240 char sh_path
[] = "/bin/sh";
241 char *argv
[] = { sh_path
,
243 "/usr/bin/hostid >/proc/sys/kernel/spl/hostid",
245 char *envp
[] = { "HOME=/",
247 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
250 /* Doing address resolution in the kernel is tricky and just
251 * not a good idea in general. So to set the proper 'hw_serial'
252 * use the usermodehelper support to ask '/bin/sh' to run
253 * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
254 * for us to use. It's a horific solution but it will do for now.
256 return call_usermodehelper(sh_path
, argv
, envp
, 1);
259 static int __init
spl_init(void)
263 if ((rc
= debug_init()))
266 if ((rc
= spl_kmem_init()))
269 if ((rc
= spl_mutex_init()))
272 if ((rc
= spl_taskq_init()))
275 if ((rc
= vn_init()))
278 if ((rc
= proc_init()))
281 if ((rc
= kstat_init()))
284 if ((rc
= set_hostid()))
285 GOTO(out7
, rc
= -EADDRNOTAVAIL
);
287 printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION
);
304 printk("SPL: Failed to Load Solaris Porting Layer v%s, "
305 "rc = %d\n", VERSION
, rc
);
309 static void spl_fini(void)
313 printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION
);
323 module_init(spl_init
);
324 module_exit(spl_fini
);
326 MODULE_AUTHOR("Lawrence Livermore National Labs");
327 MODULE_DESCRIPTION("Solaris Porting Layer");
328 MODULE_LICENSE("GPL");