Import spl_hostid as a module parameter.

Provide a call_usermodehelper() alternative by letting the hostid be passed as
a module parameter like this:

  $ modprobe spl spl_hostid=0x12345678

Internally change the spl_hostid variable to unsigned long because that is the
type that the coreutils /usr/bin/hostid returns.

Move the hostid command into GET_HOSTID_CMD for consistency with the similar
GET_KALLSYMS_ADDR_CMD invocation.

Use argv[0] instead of sh_path for consistency internally and with other Linux
drivers.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
Darik Horn 2011-04-11 14:49:50 -05:00 committed by Brian Behlendorf
parent 3dfc591ac4
commit fa6f7d8f9d
3 changed files with 18 additions and 13 deletions

View File

@ -143,7 +143,7 @@
/* Missing globals */ /* Missing globals */
extern char spl_version[16]; extern char spl_version[16];
extern long spl_hostid; extern unsigned long spl_hostid;
extern char hw_serial[11]; extern char hw_serial[11];
/* Missing misc functions */ /* Missing misc functions */

View File

@ -52,8 +52,10 @@
char spl_version[16] = "SPL v" SPL_META_VERSION; char spl_version[16] = "SPL v" SPL_META_VERSION;
EXPORT_SYMBOL(spl_version); EXPORT_SYMBOL(spl_version);
long spl_hostid = 0; unsigned long spl_hostid = 0;
EXPORT_SYMBOL(spl_hostid); EXPORT_SYMBOL(spl_hostid);
module_param(spl_hostid, ulong, 0644);
MODULE_PARM_DESC(spl_hostid, "The system hostid.");
char hw_serial[HW_HOSTID_LEN] = "<none>"; char hw_serial[HW_HOSTID_LEN] = "<none>";
EXPORT_SYMBOL(hw_serial); EXPORT_SYMBOL(hw_serial);
@ -362,13 +364,18 @@ struct new_utsname *__utsname(void)
} }
EXPORT_SYMBOL(__utsname); EXPORT_SYMBOL(__utsname);
#define GET_HOSTID_CMD \
"exec 0</dev/null " \
" 1>/proc/sys/kernel/spl/hostid " \
" 2>/dev/null; " \
"hostid"
static int static int
set_hostid(void) set_hostid(void)
{ {
char sh_path[] = "/bin/sh"; char *argv[] = { "/bin/sh",
char *argv[] = { sh_path,
"-c", "-c",
"/usr/bin/hostid >/proc/sys/kernel/spl/hostid", GET_HOSTID_CMD,
NULL }; NULL };
char *envp[] = { "HOME=/", char *envp[] = { "HOME=/",
"TERM=linux", "TERM=linux",
@ -382,7 +389,7 @@ set_hostid(void)
* '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
* for us to use. It's a horrific solution but it will do for now. * for us to use. It's a horrific solution but it will do for now.
*/ */
rc = call_usermodehelper(sh_path, argv, envp, 1); rc = call_usermodehelper(argv[0], argv, envp, 1);
if (rc) if (rc)
printk("SPL: Failed user helper '%s %s %s', rc = %d\n", printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
argv[0], argv[1], argv[2], rc); argv[0], argv[1], argv[2], rc);
@ -475,7 +482,8 @@ __init spl_init(void)
if ((rc = zlib_init())) if ((rc = zlib_init()))
SGOTO(out9, rc); SGOTO(out9, rc);
if ((rc = set_hostid())) /* Get the hostid if it was not passed as a module parameter. */
if (spl_hostid == 0 && (rc = set_hostid()))
SGOTO(out10, rc = -EADDRNOTAVAIL); SGOTO(out10, rc = -EADDRNOTAVAIL);
#ifndef HAVE_KALLSYMS_LOOKUP_NAME #ifndef HAVE_KALLSYMS_LOOKUP_NAME

View File

@ -487,7 +487,6 @@ SPL_PROC_HANDLER(proc_doslab)
SPL_PROC_HANDLER(proc_dohostid) SPL_PROC_HANDLER(proc_dohostid)
{ {
int len, rc = 0; int len, rc = 0;
int32_t val;
char *end, str[32]; char *end, str[32];
SENTRY; SENTRY;
@ -499,17 +498,15 @@ SPL_PROC_HANDLER(proc_dohostid)
if (rc < 0) if (rc < 0)
SRETURN(rc); SRETURN(rc);
val = simple_strtol(str, &end, 16); spl_hostid = simple_strtoul(str, &end, 16);
if (str == end) if (str == end)
SRETURN(-EINVAL); SRETURN(-EINVAL);
spl_hostid = (long) val; (void) snprintf(hw_serial, HW_HOSTID_LEN, "%lu", spl_hostid);
(void) snprintf(hw_serial, HW_HOSTID_LEN, "%u",
(val >= 0) ? val : -val);
hw_serial[HW_HOSTID_LEN - 1] = '\0'; hw_serial[HW_HOSTID_LEN - 1] = '\0';
*ppos += *lenp; *ppos += *lenp;
} else { } else {
len = snprintf(str, sizeof(str), "%lx", spl_hostid); len = snprintf(str, sizeof(str), "%lux", spl_hostid);
if (*ppos >= len) if (*ppos >= len)
rc = 0; rc = 0;
else else