mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
import: require force when cachefile hostid doesn't match on-disk
Previously, if a cachefile is passed to zpool import, the cached config is mostly offered as-is to ZFS_IOC_POOL_TRYIMPORT->spa_tryimport(), and the results are taken as the canonical pool config and handed back to ZFS_IOC_POOL_IMPORT. In the course of its operation, spa_load() will inspect the pool and build a new config from what it finds on disk. However, it then regenerates a new config ready to import, and so rightly sets the hostid and hostname for the local host in the config it returns. Because of this, the "require force" checks always decide the pool is exported and last touched by the local host, even if this is not true, which is possible in a HA environment when MMP is not enabled. The pool may be imported on another head, but the import checks still pass here, so the pool ends up imported on both. (This doesn't happen when a cachefile isn't used, because the pool config is discovered in userspace in zpool_find_import(), and that does find the on-disk hostid and hostname correctly). Since the systemd zfs-import-cache.service unit uses cachefile imports, this can lead to a system returning after a crash with a "valid" cachefile on disk and automatically, quietly, importing a pool that has already been taken up by a secondary head. This commit causes the on-disk hostid and hostname to be included in the ZPOOL_CONFIG_LOAD_INFO item in the returned config, and then changes the "force" checks for zpool import to use them if present. This method should give no change in behaviour for old userspace on new kernels (they won't know to look for the new config items) and for new userspace on old kernels (the won't find the new config items). Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <rob.norris@klarasystems.com> Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Closes #15290
This commit is contained in:
committed by
Brian Behlendorf
parent
8f5aa8cb00
commit
54b1b1d893
+19
-4
@@ -3122,12 +3122,21 @@ zfs_force_import_required(nvlist_t *config)
|
||||
nvlist_t *nvinfo;
|
||||
|
||||
state = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE);
|
||||
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
|
||||
nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
|
||||
|
||||
/*
|
||||
* The hostid on LOAD_INFO comes from the MOS label via
|
||||
* spa_tryimport(). If its not there then we're likely talking to an
|
||||
* older kernel, so use the top one, which will be from the label
|
||||
* discovered in zpool_find_import(), or if a cachefile is in use, the
|
||||
* local hostid.
|
||||
*/
|
||||
if (nvlist_lookup_uint64(nvinfo, ZPOOL_CONFIG_HOSTID, &hostid) != 0)
|
||||
nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
|
||||
|
||||
if (state != POOL_STATE_EXPORTED && hostid != get_system_hostid())
|
||||
return (B_TRUE);
|
||||
|
||||
nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
|
||||
if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_STATE)) {
|
||||
mmp_state_t mmp_state = fnvlist_lookup_uint64(nvinfo,
|
||||
ZPOOL_CONFIG_MMP_STATE);
|
||||
@@ -3198,7 +3207,10 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
|
||||
time_t timestamp = 0;
|
||||
uint64_t hostid = 0;
|
||||
|
||||
if (nvlist_exists(config, ZPOOL_CONFIG_HOSTNAME))
|
||||
if (nvlist_exists(nvinfo, ZPOOL_CONFIG_HOSTNAME))
|
||||
hostname = fnvlist_lookup_string(nvinfo,
|
||||
ZPOOL_CONFIG_HOSTNAME);
|
||||
else if (nvlist_exists(config, ZPOOL_CONFIG_HOSTNAME))
|
||||
hostname = fnvlist_lookup_string(config,
|
||||
ZPOOL_CONFIG_HOSTNAME);
|
||||
|
||||
@@ -3206,7 +3218,10 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
|
||||
timestamp = fnvlist_lookup_uint64(config,
|
||||
ZPOOL_CONFIG_TIMESTAMP);
|
||||
|
||||
if (nvlist_exists(config, ZPOOL_CONFIG_HOSTID))
|
||||
if (nvlist_exists(nvinfo, ZPOOL_CONFIG_HOSTID))
|
||||
hostid = fnvlist_lookup_uint64(nvinfo,
|
||||
ZPOOL_CONFIG_HOSTID);
|
||||
else if (nvlist_exists(config, ZPOOL_CONFIG_HOSTID))
|
||||
hostid = fnvlist_lookup_uint64(config,
|
||||
ZPOOL_CONFIG_HOSTID);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user