mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 18:11:00 +03:00
Determine the hostid on demand.
Currently, the SPL tries to determine the hostid at module load. The hostid is usually determined by running the userland program "hostid" during module initialization. Unfortunately, when the module initializes, it may be way too soon to be able to run any userland programs. This is especially true when the module is compiled directly inside the kernel (built-in); in that case, the SPL would try to run hostid when the kernel is still initializing, which of course is doomed to fail. This patch fixes the issue by deferring hostid generation until something actually needs the hostid (that is, when zone_get_hostid() is called), thus switching to a "on-initialization" model to a "on-demand" (lazy loading) model. ZFS only needs the hostid when some pool operations are requested, and this always happens way after the kernel has finished initialization, thus solving the problem. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue zfsonlinux/zfs#851
This commit is contained in:
parent
c167aadb27
commit
a9f2397ee9
@ -546,11 +546,29 @@ hostid_exec(void)
|
||||
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);
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
if ((spl_hostid == HW_INVALID_HOSTID) &&
|
||||
(rc = hostid_read()) && (rc = hostid_exec()))
|
||||
return HW_INVALID_HOSTID;
|
||||
|
||||
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;
|
||||
|
||||
@ -632,16 +650,6 @@ __init spl_init(void)
|
||||
if ((rc = spl_zlib_init()))
|
||||
SGOTO(out9, rc);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
if (spl_hostid == HW_INVALID_HOSTID
|
||||
&& (rc = hostid_read()) && (rc = hostid_exec()))
|
||||
SGOTO(out10, rc = -EADDRNOTAVAIL);
|
||||
|
||||
#ifndef HAVE_KALLSYMS_LOOKUP_NAME
|
||||
if ((rc = set_kallsyms_lookup_name()))
|
||||
SGOTO(out10, rc = -EADDRNOTAVAIL);
|
||||
@ -653,9 +661,8 @@ __init spl_init(void)
|
||||
if ((rc = spl_vn_init_kallsyms_lookup()))
|
||||
SGOTO(out10, rc);
|
||||
|
||||
printk(KERN_NOTICE "SPL: Loaded module v%s-%s%s, using hostid "
|
||||
"0x%08x\n", SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR,
|
||||
(unsigned int) spl_hostid);
|
||||
printk(KERN_NOTICE "SPL: Loaded module v%s-%s%s\n", SPL_META_VERSION,
|
||||
SPL_META_RELEASE, SPL_DEBUG_STR);
|
||||
SRETURN(rc);
|
||||
out10:
|
||||
spl_zlib_fini();
|
||||
|
Loading…
Reference in New Issue
Block a user