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