]> git.proxmox.com Git - mirror_zfs.git/blame - modules/spl/spl-generic.c
New an improved taskq implementation for the SPL. It allows a
[mirror_zfs.git] / modules / spl / spl-generic.c
CommitLineData
14c5326c 1#include <sys/sysmacros.h>
af828292
BB
2#include <sys/vmsystm.h>
3#include <sys/vnode.h>
c19c06f3 4#include <sys/kmem.h>
8d0f1ee9 5#include <sys/debug.h>
57d1b188 6#include <sys/proc.h>
f23e92fa 7#include <linux/kmod.h>
70eadc19 8#include "config.h"
f1b59d26 9
57d1b188
BB
10#ifdef DEBUG_SUBSYSTEM
11#undef DEBUG_SUBSYSTEM
12#endif
8d0f1ee9 13
57d1b188 14#define DEBUG_SUBSYSTEM S_GENERIC
f23e92fa 15
3561541c
BB
16char spl_version[16] = "SPL v" VERSION;
17
937879f1 18long spl_hostid = 0;
f23e92fa 19EXPORT_SYMBOL(spl_hostid);
8d0f1ee9 20
937879f1
BB
21char hw_serial[11] = "<none>";
22EXPORT_SYMBOL(hw_serial);
f1b59d26
BB
23
24int p0 = 0;
25EXPORT_SYMBOL(p0);
70eadc19 26
af828292
BB
27vmem_t *zio_alloc_arena = NULL;
28EXPORT_SYMBOL(zio_alloc_arena);
29
77b1fe8f
BB
30int
31highbit(unsigned long i)
32{
33 register int h = 1;
57d1b188 34 ENTRY;
77b1fe8f
BB
35
36 if (i == 0)
57d1b188 37 RETURN(0);
77b1fe8f
BB
38#if BITS_PER_LONG == 64
39 if (i & 0xffffffff00000000ul) {
40 h += 32; i >>= 32;
41 }
42#endif
43 if (i & 0xffff0000) {
44 h += 16; i >>= 16;
45 }
46 if (i & 0xff00) {
47 h += 8; i >>= 8;
48 }
49 if (i & 0xf0) {
50 h += 4; i >>= 4;
51 }
52 if (i & 0xc) {
53 h += 2; i >>= 2;
54 }
55 if (i & 0x2) {
56 h += 1;
57 }
57d1b188 58 RETURN(h);
77b1fe8f
BB
59}
60EXPORT_SYMBOL(highbit);
61
2f5d55aa
BB
62int
63ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result)
64{
65 char *end;
66 return (*result = simple_strtoul(str, &end, base));
67}
68EXPORT_SYMBOL(ddi_strtoul);
69
8d0f1ee9 70static int
57d1b188 71set_hostid(void)
8d0f1ee9 72{
f23e92fa
BB
73 char sh_path[] = "/bin/sh";
74 char *argv[] = { sh_path,
75 "-c",
57d1b188 76 "/usr/bin/hostid >/proc/sys/spl/hostid",
f23e92fa
BB
77 NULL };
78 char *envp[] = { "HOME=/",
79 "TERM=linux",
80 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
81 NULL };
8d0f1ee9 82
57d1b188 83 /* Doing address resolution in the kernel is tricky and just
937879f1 84 * not a good idea in general. So to set the proper 'hw_serial'
57d1b188
BB
85 * use the usermodehelper support to ask '/bin/sh' to run
86 * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
87 * for us to use. It's a horific solution but it will do for now.
88 */
89 return call_usermodehelper(sh_path, argv, envp, 1);
90}
8d0f1ee9 91
57d1b188
BB
92static int __init spl_init(void)
93{
94 int rc = 0;
f23e92fa 95
57d1b188 96 if ((rc = debug_init()))
18c9eadf 97 return rc;
f23e92fa 98
8d0f1ee9 99 if ((rc = kmem_init()))
57d1b188 100 GOTO(out , rc);
8d0f1ee9
BB
101
102 if ((rc = vn_init()))
57d1b188 103 GOTO(out2, rc);
8d0f1ee9 104
57d1b188
BB
105 if ((rc = proc_init()))
106 GOTO(out3, rc);
af828292 107
57d1b188
BB
108 if ((rc = set_hostid()))
109 GOTO(out4, rc = -EADDRNOTAVAIL);
f23e92fa 110
937879f1 111 printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION);
57d1b188 112 RETURN(rc);
f23e92fa 113out4:
57d1b188 114 proc_fini();
f23e92fa 115out3:
57d1b188 116 vn_fini();
8d0f1ee9 117out2:
57d1b188 118 kmem_fini();
8d0f1ee9 119out:
57d1b188 120 debug_fini();
8d0f1ee9 121
57d1b188
BB
122 printk("SPL: Failed to Load Solaris Porting Layer v%s, "
123 "rc = %d\n", VERSION, rc);
18c9eadf 124 return rc;
70eadc19
BB
125}
126
127static void spl_fini(void)
128{
57d1b188
BB
129 ENTRY;
130
937879f1 131 printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION);
57d1b188 132 proc_fini();
af828292 133 vn_fini();
e4f1d29f 134 kmem_fini();
57d1b188 135 debug_fini();
70eadc19
BB
136}
137
138module_init(spl_init);
139module_exit(spl_fini);
140
141MODULE_AUTHOR("Lawrence Livermore National Labs");
142MODULE_DESCRIPTION("Solaris Porting Layer");
143MODULE_LICENSE("GPL");