2010-05-17 22:18:00 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 01:26:55 +00:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2010-05-17 22:18:00 +00:00
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************
|
|
|
|
* Solaris Porting Layer (SPL) Generic Implementation.
|
|
|
|
\*****************************************************************************/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2008-03-04 18:22:31 +00:00
|
|
|
#include <sys/sysmacros.h>
|
2009-02-19 19:26:17 +00:00
|
|
|
#include <sys/systeminfo.h>
|
2008-03-14 00:04:01 +00:00
|
|
|
#include <sys/vmsystm.h>
|
2011-06-20 19:53:56 +00:00
|
|
|
#include <sys/kobj.h>
|
2008-03-14 20:56:26 +00:00
|
|
|
#include <sys/kmem.h>
|
2014-12-08 18:04:42 +00:00
|
|
|
#include <sys/kmem_cache.h>
|
|
|
|
#include <sys/vmem.h>
|
2008-05-05 20:18:49 +00:00
|
|
|
#include <sys/mutex.h>
|
2009-09-25 21:14:35 +00:00
|
|
|
#include <sys/rwlock.h>
|
2009-01-05 23:08:03 +00:00
|
|
|
#include <sys/taskq.h>
|
2010-11-30 17:51:46 +00:00
|
|
|
#include <sys/tsd.h>
|
2011-02-25 21:26:19 +00:00
|
|
|
#include <sys/zmod.h>
|
2008-03-31 20:42:36 +00:00
|
|
|
#include <sys/debug.h>
|
2008-04-18 23:39:58 +00:00
|
|
|
#include <sys/proc.h>
|
2008-05-08 23:21:47 +00:00
|
|
|
#include <sys/kstat.h>
|
2009-07-10 17:56:32 +00:00
|
|
|
#include <sys/file.h>
|
2014-12-08 18:04:42 +00:00
|
|
|
#include <linux/ctype.h>
|
2008-04-12 04:27:59 +00:00
|
|
|
#include <linux/kmod.h>
|
2014-11-14 18:18:05 +00:00
|
|
|
#include <linux/math64_compat.h>
|
2010-06-11 21:37:46 +00:00
|
|
|
#include <linux/proc_compat.h>
|
2008-04-12 04:27:59 +00:00
|
|
|
|
2012-03-23 19:03:57 +00:00
|
|
|
char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE;
|
2010-07-01 17:12:57 +00:00
|
|
|
EXPORT_SYMBOL(spl_version);
|
2008-04-24 17:41:23 +00:00
|
|
|
|
2013-03-12 01:16:36 +00:00
|
|
|
unsigned long spl_hostid = 0;
|
2008-04-12 04:27:59 +00:00
|
|
|
EXPORT_SYMBOL(spl_hostid);
|
2011-04-11 19:49:50 +00:00
|
|
|
module_param(spl_hostid, ulong, 0644);
|
|
|
|
MODULE_PARM_DESC(spl_hostid, "The system hostid.");
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2010-06-11 21:37:46 +00:00
|
|
|
proc_t p0 = { 0 };
|
2008-02-27 19:09:51 +00:00
|
|
|
EXPORT_SYMBOL(p0);
|
2008-02-27 21:56:51 +00:00
|
|
|
|
2010-07-12 19:38:34 +00:00
|
|
|
#if BITS_PER_LONG == 32
|
2008-08-11 22:42:04 +00:00
|
|
|
/*
|
2010-07-12 19:38:34 +00:00
|
|
|
* Support 64/64 => 64 division on a 32-bit platform. While the kernel
|
|
|
|
* provides a div64_u64() function for this we do not use it because the
|
|
|
|
* implementation is flawed. There are cases which return incorrect
|
|
|
|
* results as late as linux-2.6.35. Until this is fixed upstream the
|
|
|
|
* spl must provide its own implementation.
|
|
|
|
*
|
|
|
|
* This implementation is a slightly modified version of the algorithm
|
|
|
|
* proposed by the book 'Hacker's Delight'. The original source can be
|
|
|
|
* found here and is available for use without restriction.
|
|
|
|
*
|
|
|
|
* http://www.hackersdelight.org/HDcode/newCode/divDouble.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate number of leading of zeros for a 64-bit value.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nlz64(uint64_t x) {
|
|
|
|
register int n = 0;
|
|
|
|
|
|
|
|
if (x == 0)
|
|
|
|
return 64;
|
|
|
|
|
|
|
|
if (x <= 0x00000000FFFFFFFFULL) {n = n + 32; x = x << 32;}
|
|
|
|
if (x <= 0x0000FFFFFFFFFFFFULL) {n = n + 16; x = x << 16;}
|
|
|
|
if (x <= 0x00FFFFFFFFFFFFFFULL) {n = n + 8; x = x << 8;}
|
|
|
|
if (x <= 0x0FFFFFFFFFFFFFFFULL) {n = n + 4; x = x << 4;}
|
|
|
|
if (x <= 0x3FFFFFFFFFFFFFFFULL) {n = n + 2; x = x << 2;}
|
|
|
|
if (x <= 0x7FFFFFFFFFFFFFFFULL) {n = n + 1;}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Newer kernels have a div_u64() function but we define our own
|
|
|
|
* to simplify portibility between kernel versions.
|
|
|
|
*/
|
|
|
|
static inline uint64_t
|
|
|
|
__div_u64(uint64_t u, uint32_t v)
|
|
|
|
{
|
|
|
|
(void) do_div(u, v);
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of 64-bit unsigned division for 32-bit machines.
|
|
|
|
*
|
|
|
|
* First the procedure takes care of the case in which the divisor is a
|
|
|
|
* 32-bit quantity. There are two subcases: (1) If the left half of the
|
|
|
|
* dividend is less than the divisor, one execution of do_div() is all that
|
|
|
|
* is required (overflow is not possible). (2) Otherwise it does two
|
|
|
|
* divisions, using the grade school method.
|
2008-08-11 22:42:04 +00:00
|
|
|
*/
|
2010-06-03 05:01:14 +00:00
|
|
|
uint64_t
|
2010-07-12 19:38:34 +00:00
|
|
|
__udivdi3(uint64_t u, uint64_t v)
|
2008-08-11 22:42:04 +00:00
|
|
|
{
|
2010-07-12 19:38:34 +00:00
|
|
|
uint64_t u0, u1, v1, q0, q1, k;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (v >> 32 == 0) { // If v < 2**32:
|
|
|
|
if (u >> 32 < v) { // If u/v cannot overflow,
|
|
|
|
return __div_u64(u, v); // just do one division.
|
|
|
|
} else { // If u/v would overflow:
|
|
|
|
u1 = u >> 32; // Break u into two halves.
|
|
|
|
u0 = u & 0xFFFFFFFF;
|
|
|
|
q1 = __div_u64(u1, v); // First quotient digit.
|
|
|
|
k = u1 - q1 * v; // First remainder, < v.
|
|
|
|
u0 += (k << 32);
|
|
|
|
q0 = __div_u64(u0, v); // Seconds quotient digit.
|
|
|
|
return (q1 << 32) + q0;
|
|
|
|
}
|
|
|
|
} else { // If v >= 2**32:
|
|
|
|
n = nlz64(v); // 0 <= n <= 31.
|
|
|
|
v1 = (v << n) >> 32; // Normalize divisor, MSB is 1.
|
|
|
|
u1 = u >> 1; // To ensure no overflow.
|
|
|
|
q1 = __div_u64(u1, v1); // Get quotient from
|
|
|
|
q0 = (q1 << n) >> 31; // Undo normalization and
|
|
|
|
// division of u by 2.
|
|
|
|
if (q0 != 0) // Make q0 correct or
|
|
|
|
q0 = q0 - 1; // too small by 1.
|
|
|
|
if ((u - q0 * v) >= v)
|
|
|
|
q0 = q0 + 1; // Now q0 is correct.
|
2012-05-02 00:15:28 +00:00
|
|
|
|
2010-07-12 19:38:34 +00:00
|
|
|
return q0;
|
|
|
|
}
|
2008-11-03 20:34:17 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__udivdi3);
|
|
|
|
|
|
|
|
/*
|
2010-07-12 19:38:34 +00:00
|
|
|
* Implementation of 64-bit signed division for 32-bit machines.
|
|
|
|
*/
|
|
|
|
int64_t
|
|
|
|
__divdi3(int64_t u, int64_t v)
|
|
|
|
{
|
|
|
|
int64_t q, t;
|
|
|
|
q = __udivdi3(abs64(u), abs64(v));
|
|
|
|
t = (u ^ v) >> 63; // If u, v have different
|
|
|
|
return (q ^ t) - t; // signs, negate q.
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__divdi3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of 64-bit unsigned modulo for 32-bit machines.
|
2008-11-03 20:34:17 +00:00
|
|
|
*/
|
2010-06-03 05:01:14 +00:00
|
|
|
uint64_t
|
|
|
|
__umoddi3(uint64_t dividend, uint64_t divisor)
|
2008-11-03 20:34:17 +00:00
|
|
|
{
|
2010-06-03 05:01:14 +00:00
|
|
|
return (dividend - (divisor * __udivdi3(dividend, divisor)));
|
2008-08-11 22:42:04 +00:00
|
|
|
}
|
2008-11-03 20:34:17 +00:00
|
|
|
EXPORT_SYMBOL(__umoddi3);
|
2010-07-12 19:38:34 +00:00
|
|
|
|
2012-05-02 00:15:28 +00:00
|
|
|
#if defined(__arm) || defined(__arm__)
|
|
|
|
/*
|
2012-05-15 05:45:09 +00:00
|
|
|
* Implementation of 64-bit (un)signed division for 32-bit arm machines.
|
|
|
|
*
|
|
|
|
* Run-time ABI for the ARM Architecture (page 20). A pair of (unsigned)
|
|
|
|
* long longs is returned in {{r0, r1}, {r2,r3}}, the quotient in {r0, r1},
|
|
|
|
* and the remainder in {r2, r3}. The return type is specifically left
|
|
|
|
* set to 'void' to ensure the compiler does not overwrite these registers
|
|
|
|
* during the return. All results are in registers as per ABI
|
2012-05-02 00:15:28 +00:00
|
|
|
*/
|
2012-05-15 05:45:09 +00:00
|
|
|
void
|
2012-05-02 00:15:28 +00:00
|
|
|
__aeabi_uldivmod(uint64_t u, uint64_t v)
|
|
|
|
{
|
2012-05-15 05:45:09 +00:00
|
|
|
uint64_t res;
|
|
|
|
uint64_t mod;
|
|
|
|
|
|
|
|
res = __udivdi3(u, v);
|
|
|
|
mod = __umoddi3(u, v);
|
|
|
|
{
|
|
|
|
register uint32_t r0 asm("r0") = (res & 0xFFFFFFFF);
|
|
|
|
register uint32_t r1 asm("r1") = (res >> 32);
|
|
|
|
register uint32_t r2 asm("r2") = (mod & 0xFFFFFFFF);
|
|
|
|
register uint32_t r3 asm("r3") = (mod >> 32);
|
|
|
|
|
|
|
|
asm volatile(""
|
|
|
|
: "+r"(r0), "+r"(r1), "+r"(r2),"+r"(r3) /* output */
|
|
|
|
: "r"(r0), "r"(r1), "r"(r2), "r"(r3)); /* input */
|
|
|
|
|
|
|
|
return; /* r0; */
|
|
|
|
}
|
2012-05-02 00:15:28 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__aeabi_uldivmod);
|
|
|
|
|
2012-05-15 05:45:09 +00:00
|
|
|
void
|
2012-05-02 00:15:28 +00:00
|
|
|
__aeabi_ldivmod(int64_t u, int64_t v)
|
|
|
|
{
|
2012-05-15 05:45:09 +00:00
|
|
|
int64_t res;
|
|
|
|
uint64_t mod;
|
|
|
|
|
|
|
|
res = __divdi3(u, v);
|
|
|
|
mod = __umoddi3(u, v);
|
|
|
|
{
|
|
|
|
register uint32_t r0 asm("r0") = (res & 0xFFFFFFFF);
|
|
|
|
register uint32_t r1 asm("r1") = (res >> 32);
|
|
|
|
register uint32_t r2 asm("r2") = (mod & 0xFFFFFFFF);
|
|
|
|
register uint32_t r3 asm("r3") = (mod >> 32);
|
|
|
|
|
|
|
|
asm volatile(""
|
|
|
|
: "+r"(r0), "+r"(r1), "+r"(r2),"+r"(r3) /* output */
|
|
|
|
: "r"(r0), "r"(r1), "r"(r2), "r"(r3)); /* input */
|
|
|
|
|
|
|
|
return; /* r0; */
|
|
|
|
}
|
2012-05-02 00:15:28 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__aeabi_ldivmod);
|
|
|
|
#endif /* __arm || __arm__ */
|
2009-05-20 17:08:37 +00:00
|
|
|
#endif /* BITS_PER_LONG */
|
2008-08-11 22:42:04 +00:00
|
|
|
|
2009-01-13 17:30:59 +00:00
|
|
|
/* NOTE: The strtoxx behavior is solely based on my reading of the Solaris
|
|
|
|
* ddi_strtol(9F) man page. I have not verified the behavior of these
|
|
|
|
* functions against their Solaris counterparts. It is possible that I
|
2009-05-20 17:08:37 +00:00
|
|
|
* may have misinterpreted the man page or the man page is incorrect.
|
2009-01-13 17:30:59 +00:00
|
|
|
*/
|
2008-12-06 00:23:57 +00:00
|
|
|
int ddi_strtoul(const char *, char **, int, unsigned long *);
|
|
|
|
int ddi_strtol(const char *, char **, int, long *);
|
|
|
|
int ddi_strtoull(const char *, char **, int, unsigned long long *);
|
|
|
|
int ddi_strtoll(const char *, char **, int, long long *);
|
|
|
|
|
|
|
|
#define define_ddi_strtoux(type, valtype) \
|
|
|
|
int ddi_strtou##type(const char *str, char **endptr, \
|
2009-01-13 17:30:59 +00:00
|
|
|
int base, valtype *result) \
|
2008-12-06 00:23:57 +00:00
|
|
|
{ \
|
2009-01-13 17:30:59 +00:00
|
|
|
valtype last_value, value = 0; \
|
|
|
|
char *ptr = (char *)str; \
|
|
|
|
int flag = 1, digit; \
|
|
|
|
\
|
|
|
|
if (strlen(ptr) == 0) \
|
|
|
|
return EINVAL; \
|
|
|
|
\
|
|
|
|
/* Auto-detect base based on prefix */ \
|
|
|
|
if (!base) { \
|
|
|
|
if (str[0] == '0') { \
|
|
|
|
if (tolower(str[1])=='x' && isxdigit(str[2])) { \
|
|
|
|
base = 16; /* hex */ \
|
|
|
|
ptr += 2; \
|
|
|
|
} else if (str[1] >= '0' && str[1] < 8) { \
|
|
|
|
base = 8; /* octal */ \
|
|
|
|
ptr += 1; \
|
|
|
|
} else { \
|
|
|
|
return EINVAL; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
base = 10; /* decimal */ \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
while (1) { \
|
|
|
|
if (isdigit(*ptr)) \
|
|
|
|
digit = *ptr - '0'; \
|
|
|
|
else if (isalpha(*ptr)) \
|
|
|
|
digit = tolower(*ptr) - 'a' + 10; \
|
|
|
|
else \
|
|
|
|
break; \
|
|
|
|
\
|
|
|
|
if (digit >= base) \
|
|
|
|
break; \
|
2008-12-06 00:23:57 +00:00
|
|
|
\
|
2009-01-13 17:30:59 +00:00
|
|
|
last_value = value; \
|
|
|
|
value = value * base + digit; \
|
|
|
|
if (last_value > value) /* Overflow */ \
|
|
|
|
return ERANGE; \
|
2008-12-06 00:23:57 +00:00
|
|
|
\
|
2009-01-13 17:30:59 +00:00
|
|
|
flag = 1; \
|
|
|
|
ptr++; \
|
2008-12-06 00:23:57 +00:00
|
|
|
} \
|
|
|
|
\
|
2009-01-13 17:30:59 +00:00
|
|
|
if (flag) \
|
|
|
|
*result = value; \
|
|
|
|
\
|
|
|
|
if (endptr) \
|
|
|
|
*endptr = (char *)(flag ? ptr : str); \
|
|
|
|
\
|
|
|
|
return 0; \
|
2008-12-06 00:23:57 +00:00
|
|
|
} \
|
|
|
|
|
|
|
|
#define define_ddi_strtox(type, valtype) \
|
|
|
|
int ddi_strto##type(const char *str, char **endptr, \
|
|
|
|
int base, valtype *result) \
|
2009-01-13 17:30:59 +00:00
|
|
|
{ \
|
|
|
|
int rc; \
|
2008-12-06 00:23:57 +00:00
|
|
|
\
|
|
|
|
if (*str == '-') { \
|
2009-01-13 17:30:59 +00:00
|
|
|
rc = ddi_strtou##type(str + 1, endptr, base, result); \
|
|
|
|
if (!rc) { \
|
|
|
|
if (*endptr == str + 1) \
|
|
|
|
*endptr = (char *)str; \
|
|
|
|
else \
|
|
|
|
*result = -*result; \
|
|
|
|
} \
|
2008-12-06 00:23:57 +00:00
|
|
|
} else { \
|
2009-01-13 17:30:59 +00:00
|
|
|
rc = ddi_strtou##type(str, endptr, base, result); \
|
2008-12-06 00:23:57 +00:00
|
|
|
} \
|
|
|
|
\
|
2009-01-13 17:30:59 +00:00
|
|
|
return rc; \
|
|
|
|
}
|
2008-12-06 00:23:57 +00:00
|
|
|
|
|
|
|
define_ddi_strtoux(l, unsigned long)
|
|
|
|
define_ddi_strtox(l, long)
|
|
|
|
define_ddi_strtoux(ll, unsigned long long)
|
|
|
|
define_ddi_strtox(ll, long long)
|
|
|
|
|
2008-03-12 21:33:28 +00:00
|
|
|
EXPORT_SYMBOL(ddi_strtoul);
|
2008-12-06 00:23:57 +00:00
|
|
|
EXPORT_SYMBOL(ddi_strtol);
|
|
|
|
EXPORT_SYMBOL(ddi_strtoll);
|
|
|
|
EXPORT_SYMBOL(ddi_strtoull);
|
2008-03-12 21:33:28 +00:00
|
|
|
|
2009-07-10 17:56:32 +00:00
|
|
|
int
|
|
|
|
ddi_copyin(const void *from, void *to, size_t len, int flags)
|
|
|
|
{
|
|
|
|
/* Fake ioctl() issued by kernel, 'from' is a kernel address */
|
|
|
|
if (flags & FKIOCTL) {
|
|
|
|
memcpy(to, from, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copyin(from, to, len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ddi_copyin);
|
|
|
|
|
|
|
|
int
|
|
|
|
ddi_copyout(const void *from, void *to, size_t len, int flags)
|
|
|
|
{
|
|
|
|
/* Fake ioctl() issued by kernel, 'from' is a kernel address */
|
|
|
|
if (flags & FKIOCTL) {
|
|
|
|
memcpy(to, from, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copyout(from, to, len);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ddi_copyout);
|
|
|
|
|
2009-09-18 23:09:47 +00:00
|
|
|
#ifndef HAVE_PUT_TASK_STRUCT
|
|
|
|
/*
|
|
|
|
* This is only a stub function which should never be used. The SPL should
|
|
|
|
* never be putting away the last reference on a task structure so this will
|
|
|
|
* not be called. However, we still need to define it so the module does not
|
|
|
|
* have undefined symbol at load time. That all said if this impossible
|
2010-07-19 21:16:05 +00:00
|
|
|
* thing does somehow happen PANIC immediately so we know about it.
|
2009-09-18 23:09:47 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
__put_task_struct(struct task_struct *t)
|
|
|
|
{
|
2010-07-19 21:16:05 +00:00
|
|
|
PANIC("Unexpectly put last reference on task %d\n", (int)t->pid);
|
2009-09-18 23:09:47 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__put_task_struct);
|
|
|
|
#endif /* HAVE_PUT_TASK_STRUCT */
|
|
|
|
|
2011-06-20 19:53:56 +00:00
|
|
|
/*
|
|
|
|
* Read the unique system identifier from the /etc/hostid file.
|
|
|
|
*
|
|
|
|
* The behavior of /usr/bin/hostid on Linux systems with the
|
|
|
|
* regular eglibc and coreutils is:
|
|
|
|
*
|
|
|
|
* 1. Generate the value if the /etc/hostid file does not exist
|
|
|
|
* or if the /etc/hostid file is less than four bytes in size.
|
|
|
|
*
|
|
|
|
* 2. If the /etc/hostid file is at least 4 bytes, then return
|
|
|
|
* the first four bytes [0..3] in native endian order.
|
|
|
|
*
|
|
|
|
* 3. Always ignore bytes [4..] if they exist in the file.
|
|
|
|
*
|
|
|
|
* Only the first four bytes are significant, even on systems that
|
|
|
|
* have a 64-bit word size.
|
|
|
|
*
|
|
|
|
* See:
|
|
|
|
*
|
|
|
|
* eglibc: sysdeps/unix/sysv/linux/gethostid.c
|
|
|
|
* coreutils: src/hostid.c
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
*
|
|
|
|
* The /etc/hostid file on Solaris is a text file that often reads:
|
|
|
|
*
|
|
|
|
* # DO NOT EDIT
|
|
|
|
* "0123456789"
|
|
|
|
*
|
|
|
|
* Directly copying this file to Linux results in a constant
|
|
|
|
* hostid of 4f442023 because the default comment constitutes
|
|
|
|
* the first four bytes of the file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *spl_hostid_path = HW_HOSTID_PATH;
|
|
|
|
module_param(spl_hostid_path, charp, 0444);
|
|
|
|
MODULE_PARM_DESC(spl_hostid_path, "The system hostid file (/etc/hostid)");
|
|
|
|
|
|
|
|
static int
|
|
|
|
hostid_read(void)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
uint64_t size;
|
|
|
|
struct _buf *file;
|
2013-03-12 01:16:36 +00:00
|
|
|
uint32_t hostid = 0;
|
2011-06-20 19:53:56 +00:00
|
|
|
|
|
|
|
file = kobj_open_file(spl_hostid_path);
|
|
|
|
|
2011-10-06 21:55:17 +00:00
|
|
|
if (file == (struct _buf *)-1)
|
2011-06-20 19:53:56 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
result = kobj_get_filesize(file, &size);
|
|
|
|
|
|
|
|
if (result != 0) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"SPL: kobj_get_filesize returned %i on %s\n",
|
|
|
|
result, spl_hostid_path);
|
|
|
|
kobj_close_file(file);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < sizeof(HW_HOSTID_MASK)) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"SPL: Ignoring the %s file because it is %llu bytes; "
|
2012-07-20 18:12:19 +00:00
|
|
|
"expecting %lu bytes instead.\n", spl_hostid_path,
|
|
|
|
size, (unsigned long)sizeof(HW_HOSTID_MASK));
|
2011-06-20 19:53:56 +00:00
|
|
|
kobj_close_file(file);
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read directly into the variable like eglibc does. */
|
|
|
|
/* Short reads are okay; native behavior is preserved. */
|
|
|
|
result = kobj_read_file(file, (char *)&hostid, sizeof(hostid), 0);
|
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"SPL: kobj_read_file returned %i on %s\n",
|
|
|
|
result, spl_hostid_path);
|
|
|
|
kobj_close_file(file);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mask down to 32 bits like coreutils does. */
|
|
|
|
spl_hostid = hostid & HW_HOSTID_MASK;
|
|
|
|
kobj_close_file(file);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-19 19:26:17 +00:00
|
|
|
uint32_t
|
|
|
|
zone_get_hostid(void *zone)
|
|
|
|
{
|
2012-07-05 07:22:03 +00:00
|
|
|
static int first = 1;
|
2009-02-19 19:26:17 +00:00
|
|
|
|
|
|
|
/* Only the global zone is supported */
|
|
|
|
ASSERT(zone == NULL);
|
|
|
|
|
2012-07-05 07:22:03 +00:00
|
|
|
if (first) {
|
|
|
|
first = 0;
|
|
|
|
|
2015-01-23 07:01:03 +00:00
|
|
|
spl_hostid &= HW_HOSTID_MASK;
|
2012-07-05 07:22:03 +00:00
|
|
|
/*
|
|
|
|
* Get the hostid if it was not passed as a module parameter.
|
2013-03-12 01:16:36 +00:00
|
|
|
* Try reading the /etc/hostid file directly.
|
2012-07-05 07:22:03 +00:00
|
|
|
*/
|
2015-01-23 07:01:03 +00:00
|
|
|
if (spl_hostid == 0 && hostid_read())
|
2013-03-12 01:16:36 +00:00
|
|
|
spl_hostid = 0;
|
2012-07-05 07:22:03 +00:00
|
|
|
|
2015-01-23 07:01:03 +00:00
|
|
|
|
2012-07-05 07:22:03 +00:00
|
|
|
printk(KERN_NOTICE "SPL: using hostid 0x%08x\n",
|
|
|
|
(unsigned int) spl_hostid);
|
|
|
|
}
|
|
|
|
|
2013-03-12 01:16:36 +00:00
|
|
|
return spl_hostid;
|
2009-02-19 19:26:17 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zone_get_hostid);
|
|
|
|
|
2014-12-08 18:04:42 +00:00
|
|
|
static int
|
|
|
|
spl_kvmem_init(void)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
rc = spl_kmem_init();
|
|
|
|
if (rc)
|
|
|
|
goto out1;
|
|
|
|
|
|
|
|
rc = spl_vmem_init();
|
|
|
|
if (rc)
|
|
|
|
goto out2;
|
|
|
|
|
|
|
|
rc = spl_kmem_cache_init();
|
|
|
|
if (rc)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
return (rc);
|
|
|
|
out3:
|
|
|
|
spl_vmem_fini();
|
|
|
|
out2:
|
|
|
|
spl_kmem_fini();
|
|
|
|
out1:
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spl_kvmem_fini(void)
|
|
|
|
{
|
|
|
|
spl_kmem_cache_fini();
|
|
|
|
spl_vmem_fini();
|
|
|
|
spl_kmem_fini();
|
|
|
|
}
|
|
|
|
|
2009-10-01 23:06:15 +00:00
|
|
|
static int
|
|
|
|
__init spl_init(void)
|
2008-04-18 23:39:58 +00:00
|
|
|
{
|
|
|
|
int rc = 0;
|
2008-04-12 04:27:59 +00:00
|
|
|
|
2014-12-08 18:04:42 +00:00
|
|
|
if ((rc = spl_kvmem_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out1;
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2008-05-05 20:18:49 +00:00
|
|
|
if ((rc = spl_mutex_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out2;
|
2008-05-05 20:18:49 +00:00
|
|
|
|
2009-09-25 21:14:35 +00:00
|
|
|
if ((rc = spl_rw_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out3;
|
2008-03-31 20:42:36 +00:00
|
|
|
|
2009-09-25 21:14:35 +00:00
|
|
|
if ((rc = spl_taskq_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out4;
|
2008-03-14 00:04:01 +00:00
|
|
|
|
2011-11-09 20:29:51 +00:00
|
|
|
if ((rc = spl_vn_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out5;
|
2008-05-08 23:21:47 +00:00
|
|
|
|
2011-11-11 17:03:31 +00:00
|
|
|
if ((rc = spl_proc_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out6;
|
2009-01-05 23:08:03 +00:00
|
|
|
|
2011-11-11 17:03:31 +00:00
|
|
|
if ((rc = spl_kstat_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out7;
|
2009-09-25 21:14:35 +00:00
|
|
|
|
2011-11-11 17:03:31 +00:00
|
|
|
if ((rc = spl_tsd_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out8;
|
2010-11-30 17:51:46 +00:00
|
|
|
|
2011-11-11 17:03:31 +00:00
|
|
|
if ((rc = spl_zlib_init()))
|
2014-11-05 22:30:35 +00:00
|
|
|
goto out9;
|
2011-02-25 21:26:19 +00:00
|
|
|
|
2012-07-05 07:22:03 +00:00
|
|
|
printk(KERN_NOTICE "SPL: Loaded module v%s-%s%s\n", SPL_META_VERSION,
|
|
|
|
SPL_META_RELEASE, SPL_DEBUG_STR);
|
2014-11-05 22:30:35 +00:00
|
|
|
return (rc);
|
2014-10-01 23:58:11 +00:00
|
|
|
|
2010-11-30 17:51:46 +00:00
|
|
|
out9:
|
2011-11-11 17:03:31 +00:00
|
|
|
spl_tsd_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
out8:
|
2011-11-11 17:03:31 +00:00
|
|
|
spl_kstat_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
out7:
|
2011-11-11 17:03:31 +00:00
|
|
|
spl_proc_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
out6:
|
2011-11-09 20:29:51 +00:00
|
|
|
spl_vn_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
out5:
|
2009-01-05 23:08:03 +00:00
|
|
|
spl_taskq_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
out4:
|
|
|
|
spl_rw_fini();
|
2008-05-05 20:18:49 +00:00
|
|
|
out3:
|
|
|
|
spl_mutex_fini();
|
2008-03-31 20:42:36 +00:00
|
|
|
out2:
|
2014-12-08 18:04:42 +00:00
|
|
|
spl_kvmem_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
out1:
|
2012-03-23 19:03:57 +00:00
|
|
|
printk(KERN_NOTICE "SPL: Failed to Load Solaris Porting Layer "
|
|
|
|
"v%s-%s%s, rc = %d\n", SPL_META_VERSION, SPL_META_RELEASE,
|
|
|
|
SPL_DEBUG_STR, rc);
|
2014-11-05 22:30:35 +00:00
|
|
|
|
2008-04-22 22:22:02 +00:00
|
|
|
return rc;
|
2008-02-27 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 23:06:15 +00:00
|
|
|
static void
|
|
|
|
spl_fini(void)
|
2008-02-27 21:56:51 +00:00
|
|
|
{
|
2012-03-23 19:03:57 +00:00
|
|
|
printk(KERN_NOTICE "SPL: Unloaded module v%s-%s%s\n",
|
|
|
|
SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR);
|
2011-11-11 17:03:31 +00:00
|
|
|
spl_zlib_fini();
|
|
|
|
spl_tsd_fini();
|
|
|
|
spl_kstat_fini();
|
|
|
|
spl_proc_fini();
|
2011-11-09 20:29:51 +00:00
|
|
|
spl_vn_fini();
|
2009-01-05 23:08:03 +00:00
|
|
|
spl_taskq_fini();
|
2009-09-25 21:14:35 +00:00
|
|
|
spl_rw_fini();
|
2008-06-13 23:41:06 +00:00
|
|
|
spl_mutex_fini();
|
2014-12-08 18:04:42 +00:00
|
|
|
spl_kvmem_fini();
|
2008-02-27 21:56:51 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 23:06:15 +00:00
|
|
|
/* Called when a dependent module is loaded */
|
|
|
|
void
|
|
|
|
spl_setup(void)
|
|
|
|
{
|
2010-04-22 19:48:40 +00:00
|
|
|
int rc;
|
|
|
|
|
2009-10-01 23:06:15 +00:00
|
|
|
/*
|
|
|
|
* At module load time the pwd is set to '/' on a Solaris system.
|
|
|
|
* On a Linux system will be set to whatever directory the caller
|
|
|
|
* was in when executing insmod/modprobe.
|
|
|
|
*/
|
2010-04-22 19:48:40 +00:00
|
|
|
rc = vn_set_pwd("/");
|
|
|
|
if (rc)
|
|
|
|
printk("SPL: Warning unable to set pwd to '/': %d\n", rc);
|
2009-10-01 23:06:15 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(spl_setup);
|
|
|
|
|
|
|
|
/* Called when a dependent module is unloaded */
|
|
|
|
void
|
|
|
|
spl_cleanup(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(spl_cleanup);
|
|
|
|
|
2008-02-27 21:56:51 +00:00
|
|
|
module_init(spl_init);
|
|
|
|
module_exit(spl_fini);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Solaris Porting Layer");
|
2014-09-29 20:01:22 +00:00
|
|
|
MODULE_AUTHOR(SPL_META_AUTHOR);
|
|
|
|
MODULE_LICENSE(SPL_META_LICENSE);
|
2013-12-04 18:14:14 +00:00
|
|
|
MODULE_VERSION(SPL_META_VERSION "-" SPL_META_RELEASE);
|