Skip to content

Commit

Permalink
Let zpool import ignore a missing hostid record.
Browse files Browse the repository at this point in the history
Change the zpool program to skip its hostid mismatch check in the same way that
libzfs already does.

Invoked imports fail if the ZPOOL_CONFIG_HOSTID nvpair is missing in the
/etc/zfs/zpool.cache file, which can happen as of the /etc/hostid deprecation
in commit openzfs/spl@acf0ade.

Closes: openzfs#2794
  • Loading branch information
dajhorn committed Oct 13, 2014
1 parent f178ade commit 972bf60
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,37 +1914,30 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
return (1);
} else if (state != POOL_STATE_EXPORTED &&
!(flags & ZFS_IMPORT_ANY_HOST)) {
uint64_t hostid;

if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
&hostid) == 0) {
unsigned long system_hostid = gethostid() & 0xffffffff;

if ((unsigned long)hostid != system_hostid) {
char *hostname;
uint64_t timestamp;
time_t t;

verify(nvlist_lookup_string(config,
ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
verify(nvlist_lookup_uint64(config,
ZPOOL_CONFIG_TIMESTAMP, &timestamp) == 0);
t = timestamp;
(void) fprintf(stderr, gettext("cannot import "
"'%s': pool may be in use from other "
"system, it was last accessed by %s "
"(hostid: 0x%lx) on %s"), name, hostname,
(unsigned long)hostid,
asctime(localtime(&t)));
(void) fprintf(stderr, gettext("use '-f' to "
"import anyway\n"));
return (1);
}
} else {
(void) fprintf(stderr, gettext("cannot import '%s': "
"pool may be in use from other system\n"), name);
(void) fprintf(stderr, gettext("use '-f' to import "
"anyway\n"));
uint64_t hostid = 0;
unsigned long system_hostid = gethostid() & 0xffffffff;

(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
&hostid);

if (hostid != 0 && (unsigned long)hostid != system_hostid) {
char *hostname;
uint64_t timestamp;
time_t t;

verify(nvlist_lookup_string(config,
ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
verify(nvlist_lookup_uint64(config,
ZPOOL_CONFIG_TIMESTAMP, &timestamp) == 0);
t = timestamp;
(void) fprintf(stderr, gettext("cannot import "
"'%s': pool may be in use from other "
"system, it was last accessed by %s "
"(hostid: 0x%lx) on %s"), name, hostname,
(unsigned long)hostid,
asctime(localtime(&t)));
(void) fprintf(stderr, gettext("use '-f' to "
"import anyway\n"));
return (1);
}
}
Expand Down

0 comments on commit 972bf60

Please sign in to comment.