Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Simplify hostid logic #224

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/sys/sysmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
/* Missing globals */
extern char spl_version[32];
extern unsigned long spl_hostid;
extern char hw_serial[11];

/* Missing misc functions */
extern int highbit(unsigned long i);
Expand Down
1 change: 0 additions & 1 deletion include/sys/systeminfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef _SPL_SYSTEMINFO_H
#define _SPL_SYSTEMINFO_H

#define HW_INVALID_HOSTID 0xFFFFFFFF /* an invalid hostid */
#define HW_HOSTID_LEN 11 /* minimum buffer size needed */
/* to hold a decimal or hex */
/* hostid string */
Expand Down
55 changes: 6 additions & 49 deletions module/spl/spl-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@
char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE;
EXPORT_SYMBOL(spl_version);

unsigned long spl_hostid = HW_INVALID_HOSTID;
unsigned long spl_hostid = 0;
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>";
EXPORT_SYMBOL(hw_serial);

proc_t p0 = { 0 };
EXPORT_SYMBOL(p0);

Expand Down Expand Up @@ -467,7 +464,7 @@ hostid_read(void)
int result;
uint64_t size;
struct _buf *file;
unsigned long hostid = 0;
uint32_t hostid = 0;

file = kobj_open_file(spl_hostid_path);

Expand Down Expand Up @@ -511,45 +508,10 @@ hostid_read(void)
return 0;
}

#define GET_HOSTID_CMD \
"exec 0</dev/null " \
" 1>/proc/sys/kernel/spl/hostid " \
" 2>/dev/null; " \
"hostid"

static int
hostid_exec(void)
{
char *argv[] = { "/bin/sh",
"-c",
GET_HOSTID_CMD,
NULL };
char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL };
int rc;

/* Doing address resolution in the kernel is tricky and just
* not a good idea in general. So to set the proper 'hw_serial'
* use the usermodehelper support to ask '/bin/sh' to run
* '/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.
*/
rc = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
if (rc)
printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
argv[0], argv[1], argv[2], rc);

return rc;
}

uint32_t
zone_get_hostid(void *zone)
{
static int first = 1;
unsigned long hostid;
int rc;

/* Only the global zone is supported */
ASSERT(zone == NULL);
Expand All @@ -559,21 +521,16 @@ zone_get_hostid(void *zone)

/*
* Get the hostid if it was not passed as a module parameter.
* Try reading the /etc/hostid file directly, and then fall
* back to calling the /usr/bin/hostid utility.
* Try reading the /etc/hostid file directly.
*/
if ((spl_hostid == HW_INVALID_HOSTID) &&
(rc = hostid_read()) && (rc = hostid_exec()))
return HW_INVALID_HOSTID;
if (hostid_read())
spl_hostid = 0;

printk(KERN_NOTICE "SPL: using hostid 0x%08x\n",
(unsigned int) spl_hostid);
}

if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
return HW_INVALID_HOSTID;

return (uint32_t)hostid;
return spl_hostid;
}
EXPORT_SYMBOL(zone_get_hostid);

Expand Down
11 changes: 0 additions & 11 deletions module/spl/spl-proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,6 @@ SPL_PROC_HANDLER(proc_dohostid)
if (str == end)
SRETURN(-EINVAL);

(void) snprintf(hw_serial, HW_HOSTID_LEN, "%lu", spl_hostid);
hw_serial[HW_HOSTID_LEN - 1] = '\0';
*ppos += *lenp;
} else {
len = snprintf(str, sizeof(str), "%lx", spl_hostid);
if (*ppos >= len)
Expand Down Expand Up @@ -1051,14 +1048,6 @@ static struct ctl_table spl_table[] = {
.mode = 0644,
.proc_handler = &proc_dohostid,
},
{
CTL_NAME (CTL_HW_SERIAL)
.procname = "hw_serial",
.data = hw_serial,
.maxlen = sizeof(hw_serial),
.mode = 0444,
.proc_handler = &proc_dostring,
},
#ifndef HAVE_KALLSYMS_LOOKUP_NAME
{
CTL_NAME (CTL_KALLSYMS)
Expand Down