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