]> git.proxmox.com Git - mirror_spl.git/blame - module/spl/spl-generic.c
Remove Solaris module emulation
[mirror_spl.git] / module / spl / spl-generic.c
CommitLineData
716154c5
BB
1/*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
715f6251 6 * UCRL-CODE-235197
7 *
716154c5
BB
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
715f6251 15 *
716154c5 16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
715f6251 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
716154c5
BB
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting Layer (SPL) Generic Implementation.
25\*****************************************************************************/
715f6251 26
14c5326c 27#include <sys/sysmacros.h>
99639e4a 28#include <sys/systeminfo.h>
af828292 29#include <sys/vmsystm.h>
0d54dcb5 30#include <sys/kobj.h>
c19c06f3 31#include <sys/kmem.h>
9ab1ac14 32#include <sys/mutex.h>
d28db80f 33#include <sys/rwlock.h>
e9cb2b4f 34#include <sys/taskq.h>
9fe45dc1 35#include <sys/tsd.h>
5c1967eb 36#include <sys/zmod.h>
8d0f1ee9 37#include <sys/debug.h>
57d1b188 38#include <sys/proc.h>
04a479f7 39#include <sys/kstat.h>
691d2bd7 40#include <sys/utsname.h>
d3126abe 41#include <sys/file.h>
f23e92fa 42#include <linux/kmod.h>
ae4c36ad 43#include <linux/proc_compat.h>
55abb092 44#include <spl-debug.h>
f1b59d26 45
b17edc10
BB
46#ifdef SS_DEBUG_SUBSYS
47#undef SS_DEBUG_SUBSYS
57d1b188 48#endif
8d0f1ee9 49
b17edc10 50#define SS_DEBUG_SUBSYS SS_GENERIC
f23e92fa 51
0835057e 52char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE;
1a73940d 53EXPORT_SYMBOL(spl_version);
3561541c 54
0d54dcb5 55unsigned long spl_hostid = HW_INVALID_HOSTID;
f23e92fa 56EXPORT_SYMBOL(spl_hostid);
fa6f7d8f
DH
57module_param(spl_hostid, ulong, 0644);
58MODULE_PARM_DESC(spl_hostid, "The system hostid.");
8d0f1ee9 59
99639e4a 60char hw_serial[HW_HOSTID_LEN] = "<none>";
937879f1 61EXPORT_SYMBOL(hw_serial);
f1b59d26 62
ae4c36ad 63proc_t p0 = { 0 };
f1b59d26 64EXPORT_SYMBOL(p0);
70eadc19 65
d1ff2312 66#ifndef HAVE_KALLSYMS_LOOKUP_NAME
96dded38 67kallsyms_lookup_name_t spl_kallsyms_lookup_name_fn = SYMBOL_POISON;
d1ff2312
BB
68#endif
69
77b1fe8f 70int
71highbit(unsigned long i)
72{
73 register int h = 1;
b17edc10 74 SENTRY;
77b1fe8f 75
76 if (i == 0)
b17edc10 77 SRETURN(0);
77b1fe8f 78#if BITS_PER_LONG == 64
79 if (i & 0xffffffff00000000ul) {
80 h += 32; i >>= 32;
81 }
82#endif
83 if (i & 0xffff0000) {
84 h += 16; i >>= 16;
85 }
86 if (i & 0xff00) {
87 h += 8; i >>= 8;
88 }
89 if (i & 0xf0) {
90 h += 4; i >>= 4;
91 }
92 if (i & 0xc) {
93 h += 2; i >>= 2;
94 }
95 if (i & 0x2) {
96 h += 1;
97 }
b17edc10 98 SRETURN(h);
77b1fe8f 99}
100EXPORT_SYMBOL(highbit);
101
a4bfd8ea 102#if BITS_PER_LONG == 32
b61a6e8b 103/*
a4bfd8ea
BB
104 * Support 64/64 => 64 division on a 32-bit platform. While the kernel
105 * provides a div64_u64() function for this we do not use it because the
106 * implementation is flawed. There are cases which return incorrect
107 * results as late as linux-2.6.35. Until this is fixed upstream the
108 * spl must provide its own implementation.
109 *
110 * This implementation is a slightly modified version of the algorithm
111 * proposed by the book 'Hacker's Delight'. The original source can be
112 * found here and is available for use without restriction.
113 *
114 * http://www.hackersdelight.org/HDcode/newCode/divDouble.c
115 */
116
117/*
118 * Calculate number of leading of zeros for a 64-bit value.
119 */
120static int
121nlz64(uint64_t x) {
122 register int n = 0;
123
124 if (x == 0)
125 return 64;
126
127 if (x <= 0x00000000FFFFFFFFULL) {n = n + 32; x = x << 32;}
128 if (x <= 0x0000FFFFFFFFFFFFULL) {n = n + 16; x = x << 16;}
129 if (x <= 0x00FFFFFFFFFFFFFFULL) {n = n + 8; x = x << 8;}
130 if (x <= 0x0FFFFFFFFFFFFFFFULL) {n = n + 4; x = x << 4;}
131 if (x <= 0x3FFFFFFFFFFFFFFFULL) {n = n + 2; x = x << 2;}
132 if (x <= 0x7FFFFFFFFFFFFFFFULL) {n = n + 1;}
133
134 return n;
135}
136
137/*
138 * Newer kernels have a div_u64() function but we define our own
139 * to simplify portibility between kernel versions.
140 */
141static inline uint64_t
142__div_u64(uint64_t u, uint32_t v)
143{
144 (void) do_div(u, v);
145 return u;
146}
147
148/*
149 * Implementation of 64-bit unsigned division for 32-bit machines.
150 *
151 * First the procedure takes care of the case in which the divisor is a
152 * 32-bit quantity. There are two subcases: (1) If the left half of the
153 * dividend is less than the divisor, one execution of do_div() is all that
154 * is required (overflow is not possible). (2) Otherwise it does two
155 * divisions, using the grade school method.
b61a6e8b 156 */
1b4ad25e 157uint64_t
a4bfd8ea 158__udivdi3(uint64_t u, uint64_t v)
b61a6e8b 159{
a4bfd8ea
BB
160 uint64_t u0, u1, v1, q0, q1, k;
161 int n;
162
163 if (v >> 32 == 0) { // If v < 2**32:
164 if (u >> 32 < v) { // If u/v cannot overflow,
165 return __div_u64(u, v); // just do one division.
166 } else { // If u/v would overflow:
167 u1 = u >> 32; // Break u into two halves.
168 u0 = u & 0xFFFFFFFF;
169 q1 = __div_u64(u1, v); // First quotient digit.
170 k = u1 - q1 * v; // First remainder, < v.
171 u0 += (k << 32);
172 q0 = __div_u64(u0, v); // Seconds quotient digit.
173 return (q1 << 32) + q0;
174 }
175 } else { // If v >= 2**32:
176 n = nlz64(v); // 0 <= n <= 31.
177 v1 = (v << n) >> 32; // Normalize divisor, MSB is 1.
178 u1 = u >> 1; // To ensure no overflow.
179 q1 = __div_u64(u1, v1); // Get quotient from
180 q0 = (q1 << n) >> 31; // Undo normalization and
181 // division of u by 2.
182 if (q0 != 0) // Make q0 correct or
183 q0 = q0 - 1; // too small by 1.
184 if ((u - q0 * v) >= v)
185 q0 = q0 + 1; // Now q0 is correct.
ef6f91ce 186
a4bfd8ea
BB
187 return q0;
188 }
550f1705 189}
190EXPORT_SYMBOL(__udivdi3);
191
192/*
a4bfd8ea
BB
193 * Implementation of 64-bit signed division for 32-bit machines.
194 */
195int64_t
196__divdi3(int64_t u, int64_t v)
197{
198 int64_t q, t;
199 q = __udivdi3(abs64(u), abs64(v));
200 t = (u ^ v) >> 63; // If u, v have different
201 return (q ^ t) - t; // signs, negate q.
202}
203EXPORT_SYMBOL(__divdi3);
204
205/*
206 * Implementation of 64-bit unsigned modulo for 32-bit machines.
550f1705 207 */
1b4ad25e
AZ
208uint64_t
209__umoddi3(uint64_t dividend, uint64_t divisor)
550f1705 210{
1b4ad25e 211 return (dividend - (divisor * __udivdi3(dividend, divisor)));
b61a6e8b 212}
550f1705 213EXPORT_SYMBOL(__umoddi3);
a4bfd8ea 214
ef6f91ce
JL
215#if defined(__arm) || defined(__arm__)
216/*
217 * Implementation of 64-bit unsigned division for 32-bit arm machines.
218 */
219uint64_t
220__aeabi_uldivmod(uint64_t u, uint64_t v)
221{
222 return __udivdi3(u, v);
223}
224EXPORT_SYMBOL(__aeabi_uldivmod);
225
226/*
227 * Implementation of 64-bit signed division for 32-bit arm machines.
228 */
229int64_t
230__aeabi_ldivmod(int64_t u, int64_t v)
231{
232 return __divdi3(u, v);
233}
234EXPORT_SYMBOL(__aeabi_ldivmod);
235#endif /* __arm || __arm__ */
96dded38 236#endif /* BITS_PER_LONG */
b61a6e8b 237
b871b8cd
BB
238/* NOTE: The strtoxx behavior is solely based on my reading of the Solaris
239 * ddi_strtol(9F) man page. I have not verified the behavior of these
240 * functions against their Solaris counterparts. It is possible that I
96dded38 241 * may have misinterpreted the man page or the man page is incorrect.
b871b8cd 242 */
2ee63a54
BB
243int ddi_strtoul(const char *, char **, int, unsigned long *);
244int ddi_strtol(const char *, char **, int, long *);
245int ddi_strtoull(const char *, char **, int, unsigned long long *);
246int ddi_strtoll(const char *, char **, int, long long *);
247
248#define define_ddi_strtoux(type, valtype) \
249int ddi_strtou##type(const char *str, char **endptr, \
b871b8cd 250 int base, valtype *result) \
2ee63a54 251{ \
b871b8cd
BB
252 valtype last_value, value = 0; \
253 char *ptr = (char *)str; \
254 int flag = 1, digit; \
255 \
256 if (strlen(ptr) == 0) \
257 return EINVAL; \
258 \
259 /* Auto-detect base based on prefix */ \
260 if (!base) { \
261 if (str[0] == '0') { \
262 if (tolower(str[1])=='x' && isxdigit(str[2])) { \
263 base = 16; /* hex */ \
264 ptr += 2; \
265 } else if (str[1] >= '0' && str[1] < 8) { \
266 base = 8; /* octal */ \
267 ptr += 1; \
268 } else { \
269 return EINVAL; \
270 } \
271 } else { \
272 base = 10; /* decimal */ \
273 } \
274 } \
275 \
276 while (1) { \
277 if (isdigit(*ptr)) \
278 digit = *ptr - '0'; \
279 else if (isalpha(*ptr)) \
280 digit = tolower(*ptr) - 'a' + 10; \
281 else \
282 break; \
283 \
284 if (digit >= base) \
285 break; \
2ee63a54 286 \
b871b8cd
BB
287 last_value = value; \
288 value = value * base + digit; \
289 if (last_value > value) /* Overflow */ \
290 return ERANGE; \
2ee63a54 291 \
b871b8cd
BB
292 flag = 1; \
293 ptr++; \
2ee63a54
BB
294 } \
295 \
b871b8cd
BB
296 if (flag) \
297 *result = value; \
298 \
299 if (endptr) \
300 *endptr = (char *)(flag ? ptr : str); \
301 \
302 return 0; \
2ee63a54
BB
303} \
304
305#define define_ddi_strtox(type, valtype) \
306int ddi_strto##type(const char *str, char **endptr, \
307 int base, valtype *result) \
b871b8cd
BB
308{ \
309 int rc; \
2ee63a54
BB
310 \
311 if (*str == '-') { \
b871b8cd
BB
312 rc = ddi_strtou##type(str + 1, endptr, base, result); \
313 if (!rc) { \
314 if (*endptr == str + 1) \
315 *endptr = (char *)str; \
316 else \
317 *result = -*result; \
318 } \
2ee63a54 319 } else { \
b871b8cd 320 rc = ddi_strtou##type(str, endptr, base, result); \
2ee63a54
BB
321 } \
322 \
b871b8cd
BB
323 return rc; \
324}
2ee63a54
BB
325
326define_ddi_strtoux(l, unsigned long)
327define_ddi_strtox(l, long)
328define_ddi_strtoux(ll, unsigned long long)
329define_ddi_strtox(ll, long long)
330
2f5d55aa 331EXPORT_SYMBOL(ddi_strtoul);
2ee63a54
BB
332EXPORT_SYMBOL(ddi_strtol);
333EXPORT_SYMBOL(ddi_strtoll);
334EXPORT_SYMBOL(ddi_strtoull);
2f5d55aa 335
d3126abe
BB
336int
337ddi_copyin(const void *from, void *to, size_t len, int flags)
338{
339 /* Fake ioctl() issued by kernel, 'from' is a kernel address */
340 if (flags & FKIOCTL) {
341 memcpy(to, from, len);
342 return 0;
343 }
344
345 return copyin(from, to, len);
346}
347EXPORT_SYMBOL(ddi_copyin);
348
349int
350ddi_copyout(const void *from, void *to, size_t len, int flags)
351{
352 /* Fake ioctl() issued by kernel, 'from' is a kernel address */
353 if (flags & FKIOCTL) {
354 memcpy(to, from, len);
355 return 0;
356 }
357
358 return copyout(from, to, len);
359}
360EXPORT_SYMBOL(ddi_copyout);
361
e811949a
BB
362#ifndef HAVE_PUT_TASK_STRUCT
363/*
364 * This is only a stub function which should never be used. The SPL should
365 * never be putting away the last reference on a task structure so this will
366 * not be called. However, we still need to define it so the module does not
367 * have undefined symbol at load time. That all said if this impossible
55abb092 368 * thing does somehow happen PANIC immediately so we know about it.
e811949a
BB
369 */
370void
371__put_task_struct(struct task_struct *t)
372{
55abb092 373 PANIC("Unexpectly put last reference on task %d\n", (int)t->pid);
e811949a
BB
374}
375EXPORT_SYMBOL(__put_task_struct);
376#endif /* HAVE_PUT_TASK_STRUCT */
377
691d2bd7 378struct new_utsname *__utsname(void)
379{
3d061e9d 380#ifdef HAVE_INIT_UTSNAME
691d2bd7 381 return init_utsname();
3d061e9d 382#else
383 return &system_utsname;
384#endif
691d2bd7 385}
386EXPORT_SYMBOL(__utsname);
387
0d54dcb5
DH
388
389/*
390 * Read the unique system identifier from the /etc/hostid file.
391 *
392 * The behavior of /usr/bin/hostid on Linux systems with the
393 * regular eglibc and coreutils is:
394 *
395 * 1. Generate the value if the /etc/hostid file does not exist
396 * or if the /etc/hostid file is less than four bytes in size.
397 *
398 * 2. If the /etc/hostid file is at least 4 bytes, then return
399 * the first four bytes [0..3] in native endian order.
400 *
401 * 3. Always ignore bytes [4..] if they exist in the file.
402 *
403 * Only the first four bytes are significant, even on systems that
404 * have a 64-bit word size.
405 *
406 * See:
407 *
408 * eglibc: sysdeps/unix/sysv/linux/gethostid.c
409 * coreutils: src/hostid.c
410 *
411 * Notes:
412 *
413 * The /etc/hostid file on Solaris is a text file that often reads:
414 *
415 * # DO NOT EDIT
416 * "0123456789"
417 *
418 * Directly copying this file to Linux results in a constant
419 * hostid of 4f442023 because the default comment constitutes
420 * the first four bytes of the file.
421 *
422 */
423
424char *spl_hostid_path = HW_HOSTID_PATH;
425module_param(spl_hostid_path, charp, 0444);
426MODULE_PARM_DESC(spl_hostid_path, "The system hostid file (/etc/hostid)");
427
428static int
429hostid_read(void)
430{
431 int result;
432 uint64_t size;
433 struct _buf *file;
434 unsigned long hostid = 0;
435
436 file = kobj_open_file(spl_hostid_path);
437
6b3b569d 438 if (file == (struct _buf *)-1)
0d54dcb5 439 return -1;
0d54dcb5
DH
440
441 result = kobj_get_filesize(file, &size);
442
443 if (result != 0) {
444 printk(KERN_WARNING
445 "SPL: kobj_get_filesize returned %i on %s\n",
446 result, spl_hostid_path);
447 kobj_close_file(file);
448 return -2;
449 }
450
451 if (size < sizeof(HW_HOSTID_MASK)) {
452 printk(KERN_WARNING
453 "SPL: Ignoring the %s file because it is %llu bytes; "
454 "expecting %lu bytes instead.\n",
455 spl_hostid_path, size, sizeof(HW_HOSTID_MASK));
456 kobj_close_file(file);
457 return -3;
458 }
459
460 /* Read directly into the variable like eglibc does. */
461 /* Short reads are okay; native behavior is preserved. */
462 result = kobj_read_file(file, (char *)&hostid, sizeof(hostid), 0);
463
464 if (result < 0) {
465 printk(KERN_WARNING
466 "SPL: kobj_read_file returned %i on %s\n",
467 result, spl_hostid_path);
468 kobj_close_file(file);
469 return -4;
470 }
471
472 /* Mask down to 32 bits like coreutils does. */
473 spl_hostid = hostid & HW_HOSTID_MASK;
474 kobj_close_file(file);
475 return 0;
476}
477
fa6f7d8f
DH
478#define GET_HOSTID_CMD \
479 "exec 0</dev/null " \
480 " 1>/proc/sys/kernel/spl/hostid " \
481 " 2>/dev/null; " \
482 "hostid"
483
8d0f1ee9 484static int
0d54dcb5 485hostid_exec(void)
8d0f1ee9 486{
fa6f7d8f 487 char *argv[] = { "/bin/sh",
f23e92fa 488 "-c",
fa6f7d8f 489 GET_HOSTID_CMD,
f23e92fa 490 NULL };
491 char *envp[] = { "HOME=/",
492 "TERM=linux",
493 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
494 NULL };
96dded38 495 int rc;
8d0f1ee9 496
57d1b188 497 /* Doing address resolution in the kernel is tricky and just
937879f1 498 * not a good idea in general. So to set the proper 'hw_serial'
57d1b188 499 * use the usermodehelper support to ask '/bin/sh' to run
500 * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
96dded38 501 * for us to use. It's a horrific solution but it will do for now.
57d1b188 502 */
fa6f7d8f 503 rc = call_usermodehelper(argv[0], argv, envp, 1);
96dded38
BB
504 if (rc)
505 printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
506 argv[0], argv[1], argv[2], rc);
507
508 return rc;
57d1b188 509}
8d0f1ee9 510
99639e4a
BB
511uint32_t
512zone_get_hostid(void *zone)
513{
514 unsigned long hostid;
515
516 /* Only the global zone is supported */
517 ASSERT(zone == NULL);
518
519 if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
520 return HW_INVALID_HOSTID;
521
522 return (uint32_t)hostid;
523}
524EXPORT_SYMBOL(zone_get_hostid);
525
96dded38 526#ifndef HAVE_KALLSYMS_LOOKUP_NAME
d1ff2312 527/*
ad35b6a6
DH
528 * The kallsyms_lookup_name() kernel function is not an exported symbol in
529 * Linux 2.6.19 through 2.6.32 inclusive.
530 *
531 * This function replaces the functionality by performing an upcall to user
532 * space where /proc/kallsyms is consulted for the requested address.
533 *
d1ff2312 534 */
ad35b6a6
DH
535
536#define GET_KALLSYMS_ADDR_CMD \
537 "exec 0</dev/null " \
538 " 1>/proc/sys/kernel/spl/kallsyms_lookup_name " \
539 " 2>/dev/null; " \
540 "awk '{ if ( $3 == \"kallsyms_lookup_name\" ) { print $1 } }' " \
541 " /proc/kallsyms "
d1ff2312
BB
542
543static int
544set_kallsyms_lookup_name(void)
545{
ad35b6a6 546 char *argv[] = { "/bin/sh",
d1ff2312
BB
547 "-c",
548 GET_KALLSYMS_ADDR_CMD,
549 NULL };
550 char *envp[] = { "HOME=/",
551 "TERM=linux",
552 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
553 NULL };
554 int rc;
555
ad35b6a6 556 rc = call_usermodehelper(argv[0], argv, envp, 1);
d1ff2312 557 if (rc)
96dded38
BB
558 printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
559 argv[0], argv[1], argv[2], rc);
d1ff2312 560
96dded38 561 return rc;
d1ff2312
BB
562}
563#endif
564
51a727e9
BB
565static int
566__init spl_init(void)
57d1b188 567{
568 int rc = 0;
f23e92fa 569
1114ae6a 570 if ((rc = spl_debug_init()))
18c9eadf 571 return rc;
f23e92fa 572
2fb9b26a 573 if ((rc = spl_kmem_init()))
b17edc10 574 SGOTO(out1, rc);
8d0f1ee9 575
9ab1ac14 576 if ((rc = spl_mutex_init()))
b17edc10 577 SGOTO(out2, rc);
9ab1ac14 578
d28db80f 579 if ((rc = spl_rw_init()))
b17edc10 580 SGOTO(out3, rc);
8d0f1ee9 581
d28db80f 582 if ((rc = spl_taskq_init()))
b17edc10 583 SGOTO(out4, rc);
af828292 584
12ff95ff 585 if ((rc = spl_vn_init()))
b17edc10 586 SGOTO(out5, rc);
04a479f7 587
1114ae6a 588 if ((rc = spl_proc_init()))
b17edc10 589 SGOTO(out6, rc);
e9cb2b4f 590
1114ae6a 591 if ((rc = spl_kstat_init()))
b17edc10 592 SGOTO(out7, rc);
d28db80f 593
1114ae6a 594 if ((rc = spl_tsd_init()))
9fe45dc1
BB
595 SGOTO(out8, rc);
596
1114ae6a 597 if ((rc = spl_zlib_init()))
5c1967eb
BB
598 SGOTO(out9, rc);
599
0d54dcb5
DH
600 /*
601 * Get the hostid if it was not passed as a module parameter. Try
602 * reading the /etc/hostid file directly, and then fall back to calling
603 * the /usr/bin/hostid utility.
604 */
605
606 if (spl_hostid == HW_INVALID_HOSTID
607 && (rc = hostid_read()) && (rc = hostid_exec()))
5c1967eb 608 SGOTO(out10, rc = -EADDRNOTAVAIL);
f23e92fa 609
96dded38 610#ifndef HAVE_KALLSYMS_LOOKUP_NAME
d1ff2312 611 if ((rc = set_kallsyms_lookup_name()))
5c1967eb 612 SGOTO(out10, rc = -EADDRNOTAVAIL);
96dded38
BB
613#endif /* HAVE_KALLSYMS_LOOKUP_NAME */
614
615 if ((rc = spl_kmem_init_kallsyms_lookup()))
5c1967eb 616 SGOTO(out10, rc);
d1ff2312 617
12ff95ff
BB
618 if ((rc = spl_vn_init_kallsyms_lookup()))
619 SGOTO(out10, rc);
620
0835057e
BB
621 printk(KERN_NOTICE "SPL: Loaded module v%s-%s%s, using hostid "
622 "0x%08x\n", SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR,
623 (unsigned int) spl_hostid);
b17edc10 624 SRETURN(rc);
5c1967eb 625out10:
1114ae6a 626 spl_zlib_fini();
9fe45dc1 627out9:
1114ae6a 628 spl_tsd_fini();
d28db80f 629out8:
1114ae6a 630 spl_kstat_fini();
d28db80f 631out7:
1114ae6a 632 spl_proc_fini();
d28db80f 633out6:
12ff95ff 634 spl_vn_fini();
d28db80f 635out5:
e9cb2b4f 636 spl_taskq_fini();
d28db80f
BB
637out4:
638 spl_rw_fini();
9ab1ac14 639out3:
640 spl_mutex_fini();
8d0f1ee9 641out2:
2fb9b26a 642 spl_kmem_fini();
d28db80f 643out1:
1114ae6a 644 spl_debug_fini();
8d0f1ee9 645
0835057e
BB
646 printk(KERN_NOTICE "SPL: Failed to Load Solaris Porting Layer "
647 "v%s-%s%s, rc = %d\n", SPL_META_VERSION, SPL_META_RELEASE,
648 SPL_DEBUG_STR, rc);
18c9eadf 649 return rc;
70eadc19 650}
651
51a727e9
BB
652static void
653spl_fini(void)
70eadc19 654{
b17edc10 655 SENTRY;
57d1b188 656
0835057e
BB
657 printk(KERN_NOTICE "SPL: Unloaded module v%s-%s%s\n",
658 SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR);
1114ae6a
BB
659 spl_zlib_fini();
660 spl_tsd_fini();
661 spl_kstat_fini();
662 spl_proc_fini();
12ff95ff 663 spl_vn_fini();
e9cb2b4f 664 spl_taskq_fini();
d28db80f 665 spl_rw_fini();
2fb9b26a 666 spl_mutex_fini();
667 spl_kmem_fini();
1114ae6a 668 spl_debug_fini();
70eadc19 669}
670
51a727e9
BB
671/* Called when a dependent module is loaded */
672void
673spl_setup(void)
674{
82a358d9
BB
675 int rc;
676
51a727e9
BB
677 /*
678 * At module load time the pwd is set to '/' on a Solaris system.
679 * On a Linux system will be set to whatever directory the caller
680 * was in when executing insmod/modprobe.
681 */
82a358d9
BB
682 rc = vn_set_pwd("/");
683 if (rc)
684 printk("SPL: Warning unable to set pwd to '/': %d\n", rc);
51a727e9
BB
685}
686EXPORT_SYMBOL(spl_setup);
687
688/* Called when a dependent module is unloaded */
689void
690spl_cleanup(void)
691{
692}
693EXPORT_SYMBOL(spl_cleanup);
694
70eadc19 695module_init(spl_init);
696module_exit(spl_fini);
697
698MODULE_AUTHOR("Lawrence Livermore National Labs");
699MODULE_DESCRIPTION("Solaris Porting Layer");
700MODULE_LICENSE("GPL");