]> git.proxmox.com Git - mirror_spl-debian.git/blame - modules/spl/spl-generic.c
Give it a real version for a tag
[mirror_spl-debian.git] / modules / spl / spl-generic.c
CommitLineData
14c5326c 1#include <sys/sysmacros.h>
af828292 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 10#ifdef DEBUG_SUBSYSTEM
11#undef DEBUG_SUBSYSTEM
12#endif
8d0f1ee9 13
57d1b188 14#define DEBUG_SUBSYSTEM S_GENERIC
f23e92fa 15
937879f1 16long spl_hostid = 0;
f23e92fa 17EXPORT_SYMBOL(spl_hostid);
8d0f1ee9 18
937879f1 19char hw_serial[11] = "<none>";
20EXPORT_SYMBOL(hw_serial);
f1b59d26 21
22int p0 = 0;
23EXPORT_SYMBOL(p0);
70eadc19 24
af828292 25vmem_t *zio_alloc_arena = NULL;
26EXPORT_SYMBOL(zio_alloc_arena);
27
77b1fe8f 28int
29highbit(unsigned long i)
30{
31 register int h = 1;
57d1b188 32 ENTRY;
77b1fe8f 33
34 if (i == 0)
57d1b188 35 RETURN(0);
77b1fe8f 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 }
57d1b188 56 RETURN(h);
77b1fe8f 57}
58EXPORT_SYMBOL(highbit);
59
2f5d55aa 60int
61ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result)
62{
63 char *end;
64 return (*result = simple_strtoul(str, &end, base));
65}
66EXPORT_SYMBOL(ddi_strtoul);
67
8d0f1ee9 68static int
57d1b188 69set_hostid(void)
8d0f1ee9 70{
f23e92fa 71 char sh_path[] = "/bin/sh";
72 char *argv[] = { sh_path,
73 "-c",
57d1b188 74 "/usr/bin/hostid >/proc/sys/spl/hostid",
f23e92fa 75 NULL };
76 char *envp[] = { "HOME=/",
77 "TERM=linux",
78 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
79 NULL };
8d0f1ee9 80
57d1b188 81 /* Doing address resolution in the kernel is tricky and just
937879f1 82 * not a good idea in general. So to set the proper 'hw_serial'
57d1b188 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}
8d0f1ee9 89
57d1b188 90static int __init spl_init(void)
91{
92 int rc = 0;
93 ENTRY;
f23e92fa 94
57d1b188 95 if ((rc = debug_init()))
96 RETURN(rc);
f23e92fa 97
8d0f1ee9 98 if ((rc = kmem_init()))
57d1b188 99 GOTO(out , rc);
8d0f1ee9 100
101 if ((rc = vn_init()))
57d1b188 102 GOTO(out2, rc);
8d0f1ee9 103
57d1b188 104 if ((rc = proc_init()))
105 GOTO(out3, rc);
af828292 106
57d1b188 107 if ((rc = set_hostid()))
108 GOTO(out4, rc = -EADDRNOTAVAIL);
f23e92fa 109
937879f1 110 printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION);
57d1b188 111 RETURN(rc);
f23e92fa 112out4:
57d1b188 113 proc_fini();
f23e92fa 114out3:
57d1b188 115 vn_fini();
8d0f1ee9 116out2:
57d1b188 117 kmem_fini();
8d0f1ee9 118out:
57d1b188 119 debug_fini();
8d0f1ee9 120
57d1b188 121 printk("SPL: Failed to Load Solaris Porting Layer v%s, "
122 "rc = %d\n", VERSION, rc);
123 RETURN(rc);
70eadc19 124}
125
126static void spl_fini(void)
127{
57d1b188 128 ENTRY;
129
937879f1 130 printk("SPL: Unloaded Solaris Porting Layer v%s\n", VERSION);
57d1b188 131 proc_fini();
af828292 132 vn_fini();
e4f1d29f 133 kmem_fini();
57d1b188 134 debug_fini();
c19c06f3 135
57d1b188 136 EXIT;
70eadc19 137}
138
139module_init(spl_init);
140module_exit(spl_fini);
141
142MODULE_AUTHOR("Lawrence Livermore National Labs");
143MODULE_DESCRIPTION("Solaris Porting Layer");
144MODULE_LICENSE("GPL");