summaryrefslogtreecommitdiffstats
path: root/module/zfs/spa.c
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2017-12-18 10:28:27 -0800
committerGitHub <[email protected]>2017-12-18 10:28:27 -0800
commitbbffb59efc49baba1d131d497202e8cda0068c3d (patch)
tree82cce8b5379ffd834cc169f5a38ea507f437e305 /module/zfs/spa.c
parente2d936e0f893084384a0d29ddf2edfd9f68deaf2 (diff)
Fix multihost stale cache file import
When the multihost property is enabled it should be impossible to import an active pool even using the force (-f) option. This patch prevents a forced import from succeeding when importing with a stale cache file. The root cause of the problem is that the kernel modules trusted the hostid provided in configuration. This is always correct when the configuration is generated by scanning for the pool. However, when using an existing cache file the hostid could be stale which would result in the activity check being skipped. Resolve the issue by always using the hostid read from the label configuration where the best uberblock was found. Reviewed-by: Olaf Faaland <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #6933 Closes #6971
Diffstat (limited to 'module/zfs/spa.c')
-rw-r--r--module/zfs/spa.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/module/zfs/spa.c b/module/zfs/spa.c
index e06190f9d..8844b9f7b 100644
--- a/module/zfs/spa.c
+++ b/module/zfs/spa.c
@@ -2330,7 +2330,8 @@ vdev_count_verify_zaps(vdev_t *vd)
* Determine whether the activity check is required.
*/
static boolean_t
-spa_activity_check_required(spa_t *spa, uberblock_t *ub, nvlist_t *config)
+spa_activity_check_required(spa_t *spa, uberblock_t *ub, nvlist_t *label,
+ nvlist_t *config)
{
uint64_t state = 0;
uint64_t hostid = 0;
@@ -2347,7 +2348,6 @@ spa_activity_check_required(spa_t *spa, uberblock_t *ub, nvlist_t *config)
}
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE, &state);
- (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
/*
* Disable the MMP activity check - This is used by zdb which
@@ -2373,8 +2373,12 @@ spa_activity_check_required(spa_t *spa, uberblock_t *ub, nvlist_t *config)
/*
* Allow the activity check to be skipped when importing the pool
- * on the same host which last imported it.
+ * on the same host which last imported it. Since the hostid from
+ * configuration may be stale use the one read from the label.
*/
+ if (nvlist_exists(label, ZPOOL_CONFIG_HOSTID))
+ hostid = fnvlist_lookup_uint64(label, ZPOOL_CONFIG_HOSTID);
+
if (hostid == spa_get_hostid())
return (B_FALSE);
@@ -2639,7 +2643,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
* pool is truly inactive and can be safely imported. Prevent
* hosts which don't have a hostid set from importing the pool.
*/
- activity_check = spa_activity_check_required(spa, ub, config);
+ activity_check = spa_activity_check_required(spa, ub, label, config);
if (activity_check) {
if (ub->ub_mmp_magic == MMP_MAGIC && ub->ub_mmp_delay &&
spa_get_hostid() == 0) {