]>
Commit | Line | Data |
---|---|---|
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> |
8d0f1ee9 | 32 | #include <sys/debug.h> |
57d1b188 | 33 | #include <sys/proc.h> |
04a479f7 | 34 | #include <sys/kstat.h> |
f23e92fa | 35 | #include <linux/kmod.h> |
f1b59d26 | 36 | |
57d1b188 | 37 | #ifdef DEBUG_SUBSYSTEM |
38 | #undef DEBUG_SUBSYSTEM | |
39 | #endif | |
8d0f1ee9 | 40 | |
57d1b188 | 41 | #define DEBUG_SUBSYSTEM S_GENERIC |
f23e92fa | 42 | |
3561541c | 43 | char spl_version[16] = "SPL v" VERSION; |
44 | ||
937879f1 | 45 | long spl_hostid = 0; |
f23e92fa | 46 | EXPORT_SYMBOL(spl_hostid); |
8d0f1ee9 | 47 | |
937879f1 | 48 | char hw_serial[11] = "<none>"; |
49 | EXPORT_SYMBOL(hw_serial); | |
f1b59d26 | 50 | |
51 | int p0 = 0; | |
52 | EXPORT_SYMBOL(p0); | |
70eadc19 | 53 | |
af828292 | 54 | vmem_t *zio_alloc_arena = NULL; |
55 | EXPORT_SYMBOL(zio_alloc_arena); | |
56 | ||
77b1fe8f | 57 | int |
58 | highbit(unsigned long i) | |
59 | { | |
60 | register int h = 1; | |
57d1b188 | 61 | ENTRY; |
77b1fe8f | 62 | |
63 | if (i == 0) | |
57d1b188 | 64 | RETURN(0); |
77b1fe8f | 65 | #if BITS_PER_LONG == 64 |
66 | if (i & 0xffffffff00000000ul) { | |
67 | h += 32; i >>= 32; | |
68 | } | |
69 | #endif | |
70 | if (i & 0xffff0000) { | |
71 | h += 16; i >>= 16; | |
72 | } | |
73 | if (i & 0xff00) { | |
74 | h += 8; i >>= 8; | |
75 | } | |
76 | if (i & 0xf0) { | |
77 | h += 4; i >>= 4; | |
78 | } | |
79 | if (i & 0xc) { | |
80 | h += 2; i >>= 2; | |
81 | } | |
82 | if (i & 0x2) { | |
83 | h += 1; | |
84 | } | |
57d1b188 | 85 | RETURN(h); |
77b1fe8f | 86 | } |
87 | EXPORT_SYMBOL(highbit); | |
88 | ||
2f5d55aa | 89 | int |
90 | ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result) | |
91 | { | |
92 | char *end; | |
93 | return (*result = simple_strtoul(str, &end, base)); | |
94 | } | |
95 | EXPORT_SYMBOL(ddi_strtoul); | |
96 | ||
8d0f1ee9 | 97 | static int |
57d1b188 | 98 | set_hostid(void) |
8d0f1ee9 | 99 | { |
f23e92fa | 100 | char sh_path[] = "/bin/sh"; |
101 | char *argv[] = { sh_path, | |
102 | "-c", | |
57d86234 | 103 | "/usr/bin/hostid >/proc/sys/kernel/spl/hostid", |
f23e92fa | 104 | NULL }; |
105 | char *envp[] = { "HOME=/", | |
106 | "TERM=linux", | |
107 | "PATH=/sbin:/usr/sbin:/bin:/usr/bin", | |
108 | NULL }; | |
8d0f1ee9 | 109 | |
57d1b188 | 110 | /* Doing address resolution in the kernel is tricky and just |
937879f1 | 111 | * not a good idea in general. So to set the proper 'hw_serial' |
57d1b188 | 112 | * use the usermodehelper support to ask '/bin/sh' to run |
113 | * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid | |
114 | * for us to use. It's a horific solution but it will do for now. | |
115 | */ | |
116 | return call_usermodehelper(sh_path, argv, envp, 1); | |
117 | } | |
8d0f1ee9 | 118 | |
57d1b188 | 119 | static int __init spl_init(void) |
120 | { | |
121 | int rc = 0; | |
f23e92fa | 122 | |
57d1b188 | 123 | if ((rc = debug_init())) |
18c9eadf | 124 | return rc; |
f23e92fa | 125 | |
8d0f1ee9 | 126 | if ((rc = kmem_init())) |
57d1b188 | 127 | GOTO(out , rc); |
8d0f1ee9 | 128 | |
9ab1ac14 | 129 | if ((rc = spl_mutex_init())) |
130 | GOTO(out2 , rc); | |
131 | ||
8d0f1ee9 | 132 | if ((rc = vn_init())) |
9ab1ac14 | 133 | GOTO(out3, rc); |
8d0f1ee9 | 134 | |
57d1b188 | 135 | if ((rc = proc_init())) |
9ab1ac14 | 136 | GOTO(out4, rc); |
af828292 | 137 | |
04a479f7 | 138 | if ((rc = kstat_init())) |
139 | GOTO(out5, rc); | |
140 | ||
57d1b188 | 141 | if ((rc = set_hostid())) |
04a479f7 | 142 | GOTO(out6, rc = -EADDRNOTAVAIL); |
f23e92fa | 143 | |
937879f1 | 144 | printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION); |
57d1b188 | 145 | RETURN(rc); |
04a479f7 | 146 | out6: |
147 | kstat_fini(); | |
9ab1ac14 | 148 | out5: |
57d1b188 | 149 | proc_fini(); |
9ab1ac14 | 150 | out4: |
57d1b188 | 151 | vn_fini(); |
9ab1ac14 | 152 | out3: |
153 | spl_mutex_fini(); | |
8d0f1ee9 | 154 | out2: |
57d1b188 | 155 | kmem_fini(); |
8d0f1ee9 | 156 | out: |
57d1b188 | 157 | debug_fini(); |
8d0f1ee9 | 158 | |
57d1b188 | 159 | printk("SPL: Failed to Load Solaris Porting Layer v%s, " |
160 | "rc = %d\n", VERSION, rc); | |
18c9eadf | 161 | return rc; |
70eadc19 | 162 | } |
163 | ||
164 | static void spl_fini(void) | |
165 | { | |
57d1b188 | 166 | ENTRY; |
167 | ||
937879f1 | 168 | printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION); |
04a479f7 | 169 | kstat_fini(); |
57d1b188 | 170 | proc_fini(); |
af828292 | 171 | vn_fini(); |
e4f1d29f | 172 | kmem_fini(); |
57d1b188 | 173 | debug_fini(); |
70eadc19 | 174 | } |
175 | ||
176 | module_init(spl_init); | |
177 | module_exit(spl_fini); | |
178 | ||
179 | MODULE_AUTHOR("Lawrence Livermore National Labs"); | |
180 | MODULE_DESCRIPTION("Solaris Porting Layer"); | |
181 | MODULE_LICENSE("GPL"); |