mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 03:37:45 +03:00
Multi-modifier protection (MMP)
Add multihost=on|off pool property to control MMP. When enabled a new thread writes uberblocks to the last slot in each label, at a set frequency, to indicate to other hosts the pool is actively imported. These uberblocks are the last synced uberblock with an updated timestamp. Property defaults to off. During tryimport, find the "best" uberblock (newest txg and timestamp) repeatedly, checking for change in the found uberblock. Include the results of the activity test in the config returned by tryimport. These results are reported to user in "zpool import". Allow the user to control the period between MMP writes, and the duration of the activity test on import, via a new module parameter zfs_multihost_interval. The period is specified in milliseconds. The activity test duration is calculated from this value, and from the mmp_delay in the "best" uberblock found initially. Add a kstat interface to export statistics about Multiple Modifier Protection (MMP) updates. Include the last synced txg number, the timestamp, the delay since the last MMP update, the VDEV GUID, the VDEV label that received the last MMP update, and the VDEV path. Abbreviated output below. $ cat /proc/spl/kstat/zfs/mypool/multihost 31 0 0x01 10 880 105092382393521 105144180101111 txg timestamp mmp_delay vdev_guid vdev_label vdev_path 20468 261337 250274925 68396651780 3 /dev/sda 20468 261339 252023374 6267402363293 1 /dev/sdc 20468 261340 252000858 6698080955233 1 /dev/sdx 20468 261341 251980635 783892869810 2 /dev/sdy 20468 261342 253385953 8923255792467 3 /dev/sdd 20468 261344 253336622 042125143176 0 /dev/sdab 20468 261345 253310522 1200778101278 2 /dev/sde 20468 261346 253286429 0950576198362 2 /dev/sdt 20468 261347 253261545 96209817917 3 /dev/sds 20468 261349 253238188 8555725937673 3 /dev/sdb Add a new tunable zfs_multihost_history to specify the number of MMP updates to store history for. By default it is set to zero meaning that no MMP statistics are stored. When using ztest to generate activity, for automated tests of the MMP function, some test functions interfere with the test. For example, the pool is exported to run zdb and then imported again. Add a new ztest function, "-M", to alter ztest behavior to prevent this. Add new tests to verify the new functionality. Tests provided by Giuseppe Di Natale. Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov> Reviewed-by: Ned Bass <bass6@llnl.gov> Reviewed-by: Andreas Dilger <andreas.dilger@intel.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Olaf Faaland <faaland1@llnl.gov> Closes #745 Closes #6279
This commit is contained in:
committed by
Brian Behlendorf
parent
34ae0ae174
commit
379ca9cf2b
+254
-29
@@ -55,6 +55,7 @@
|
||||
#include <sys/vdev_disk.h>
|
||||
#include <sys/metaslab.h>
|
||||
#include <sys/metaslab_impl.h>
|
||||
#include <sys/mmp.h>
|
||||
#include <sys/uberblock_impl.h>
|
||||
#include <sys/txg.h>
|
||||
#include <sys/avl.h>
|
||||
@@ -491,6 +492,16 @@ spa_prop_validate(spa_t *spa, nvlist_t *props)
|
||||
error = SET_ERROR(EINVAL);
|
||||
break;
|
||||
|
||||
case ZPOOL_PROP_MULTIHOST:
|
||||
error = nvpair_value_uint64(elem, &intval);
|
||||
if (!error && intval > 1)
|
||||
error = SET_ERROR(EINVAL);
|
||||
|
||||
if (!error && !spa_get_hostid())
|
||||
error = SET_ERROR(ENOTSUP);
|
||||
|
||||
break;
|
||||
|
||||
case ZPOOL_PROP_BOOTFS:
|
||||
/*
|
||||
* If the pool version is less than SPA_VERSION_BOOTFS,
|
||||
@@ -1346,6 +1357,9 @@ spa_unload(spa_t *spa)
|
||||
spa_config_exit(spa, SCL_ALL, FTAG);
|
||||
}
|
||||
|
||||
if (spa->spa_mmp.mmp_thread)
|
||||
mmp_thread_stop(spa);
|
||||
|
||||
/*
|
||||
* Wait for any outstanding async I/O to complete.
|
||||
*/
|
||||
@@ -2323,6 +2337,197 @@ vdev_count_verify_zaps(vdev_t *vd)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Determine whether the activity check is required.
|
||||
*/
|
||||
static boolean_t
|
||||
spa_activity_check_required(spa_t *spa, uberblock_t *ub, nvlist_t *config)
|
||||
{
|
||||
uint64_t state = 0;
|
||||
uint64_t hostid = 0;
|
||||
uint64_t tryconfig_txg = 0;
|
||||
uint64_t tryconfig_timestamp = 0;
|
||||
nvlist_t *nvinfo;
|
||||
|
||||
if (nvlist_exists(config, ZPOOL_CONFIG_LOAD_INFO)) {
|
||||
nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
|
||||
(void) nvlist_lookup_uint64(nvinfo, ZPOOL_CONFIG_MMP_TXG,
|
||||
&tryconfig_txg);
|
||||
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_TIMESTAMP,
|
||||
&tryconfig_timestamp);
|
||||
}
|
||||
|
||||
(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
|
||||
* is intended to be used on potentially active pools.
|
||||
*/
|
||||
if (spa->spa_import_flags & ZFS_IMPORT_SKIP_MMP)
|
||||
return (B_FALSE);
|
||||
|
||||
/*
|
||||
* Skip the activity check when the MMP feature is disabled.
|
||||
*/
|
||||
if (ub->ub_mmp_magic == MMP_MAGIC && ub->ub_mmp_delay == 0)
|
||||
return (B_FALSE);
|
||||
/*
|
||||
* If the tryconfig_* values are nonzero, they are the results of an
|
||||
* earlier tryimport. If they match the uberblock we just found, then
|
||||
* the pool has not changed and we return false so we do not test a
|
||||
* second time.
|
||||
*/
|
||||
if (tryconfig_txg && tryconfig_txg == ub->ub_txg &&
|
||||
tryconfig_timestamp && tryconfig_timestamp == ub->ub_timestamp)
|
||||
return (B_FALSE);
|
||||
|
||||
/*
|
||||
* Allow the activity check to be skipped when importing the pool
|
||||
* on the same host which last imported it.
|
||||
*/
|
||||
if (hostid == spa_get_hostid())
|
||||
return (B_FALSE);
|
||||
|
||||
/*
|
||||
* Skip the activity test when the pool was cleanly exported.
|
||||
*/
|
||||
if (state != POOL_STATE_ACTIVE)
|
||||
return (B_FALSE);
|
||||
|
||||
return (B_TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the import activity check. If the user canceled the import or
|
||||
* we detected activity then fail.
|
||||
*/
|
||||
static int
|
||||
spa_activity_check(spa_t *spa, uberblock_t *ub, nvlist_t *config)
|
||||
{
|
||||
uint64_t import_intervals = MAX(zfs_multihost_import_intervals, 1);
|
||||
uint64_t txg = ub->ub_txg;
|
||||
uint64_t timestamp = ub->ub_timestamp;
|
||||
uint64_t import_delay = NANOSEC;
|
||||
hrtime_t import_expire;
|
||||
nvlist_t *mmp_label = NULL;
|
||||
vdev_t *rvd = spa->spa_root_vdev;
|
||||
kcondvar_t cv;
|
||||
kmutex_t mtx;
|
||||
int error = 0;
|
||||
|
||||
cv_init(&cv, NULL, CV_DEFAULT, NULL);
|
||||
mutex_init(&mtx, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_enter(&mtx);
|
||||
|
||||
/*
|
||||
* If ZPOOL_CONFIG_MMP_TXG is present an activity check was performed
|
||||
* during the earlier tryimport. If the txg recorded there is 0 then
|
||||
* the pool is known to be active on another host.
|
||||
*
|
||||
* Otherwise, the pool might be in use on another node. Check for
|
||||
* changes in the uberblocks on disk if necessary.
|
||||
*/
|
||||
if (nvlist_exists(config, ZPOOL_CONFIG_LOAD_INFO)) {
|
||||
nvlist_t *nvinfo = fnvlist_lookup_nvlist(config,
|
||||
ZPOOL_CONFIG_LOAD_INFO);
|
||||
|
||||
if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_TXG) &&
|
||||
fnvlist_lookup_uint64(nvinfo, ZPOOL_CONFIG_MMP_TXG) == 0) {
|
||||
vdev_uberblock_load(rvd, ub, &mmp_label);
|
||||
error = SET_ERROR(EREMOTEIO);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Preferentially use the zfs_multihost_interval from the node which
|
||||
* last imported the pool. This value is stored in an MMP uberblock as.
|
||||
*
|
||||
* ub_mmp_delay * vdev_count_leaves() == zfs_multihost_interval
|
||||
*/
|
||||
if (ub->ub_mmp_magic == MMP_MAGIC && ub->ub_mmp_delay)
|
||||
import_delay = MAX(import_delay, import_intervals *
|
||||
ub->ub_mmp_delay * vdev_count_leaves(spa));
|
||||
|
||||
/* Apply a floor using the local default values. */
|
||||
import_delay = MAX(import_delay, import_intervals *
|
||||
MSEC2NSEC(MAX(zfs_multihost_interval, MMP_MIN_INTERVAL)));
|
||||
|
||||
/* Add a small random factor in case of simultaneous imports (0-25%) */
|
||||
import_expire = gethrtime() + import_delay +
|
||||
(import_delay * spa_get_random(250) / 1000);
|
||||
|
||||
while (gethrtime() < import_expire) {
|
||||
vdev_uberblock_load(rvd, ub, &mmp_label);
|
||||
|
||||
if (txg != ub->ub_txg || timestamp != ub->ub_timestamp) {
|
||||
error = SET_ERROR(EREMOTEIO);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mmp_label) {
|
||||
nvlist_free(mmp_label);
|
||||
mmp_label = NULL;
|
||||
}
|
||||
|
||||
error = cv_timedwait_sig(&cv, &mtx, ddi_get_lbolt() + hz);
|
||||
if (error != -1) {
|
||||
error = SET_ERROR(EINTR);
|
||||
break;
|
||||
}
|
||||
error = 0;
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_exit(&mtx);
|
||||
mutex_destroy(&mtx);
|
||||
cv_destroy(&cv);
|
||||
|
||||
/*
|
||||
* If the pool is determined to be active store the status in the
|
||||
* spa->spa_load_info nvlist. If the remote hostname or hostid are
|
||||
* available from configuration read from disk store them as well.
|
||||
* This allows 'zpool import' to generate a more useful message.
|
||||
*
|
||||
* ZPOOL_CONFIG_MMP_STATE - observed pool status (mandatory)
|
||||
* ZPOOL_CONFIG_MMP_HOSTNAME - hostname from the active pool
|
||||
* ZPOOL_CONFIG_MMP_HOSTID - hostid from the active pool
|
||||
*/
|
||||
if (error == EREMOTEIO) {
|
||||
char *hostname = "<unknown>";
|
||||
uint64_t hostid = 0;
|
||||
|
||||
if (mmp_label) {
|
||||
if (nvlist_exists(mmp_label, ZPOOL_CONFIG_HOSTNAME)) {
|
||||
hostname = fnvlist_lookup_string(mmp_label,
|
||||
ZPOOL_CONFIG_HOSTNAME);
|
||||
fnvlist_add_string(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_HOSTNAME, hostname);
|
||||
}
|
||||
|
||||
if (nvlist_exists(mmp_label, ZPOOL_CONFIG_HOSTID)) {
|
||||
hostid = fnvlist_lookup_uint64(mmp_label,
|
||||
ZPOOL_CONFIG_HOSTID);
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_HOSTID, hostid);
|
||||
}
|
||||
}
|
||||
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_STATE, MMP_STATE_ACTIVE);
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_TXG, 0);
|
||||
|
||||
error = spa_vdev_err(rvd, VDEV_AUX_ACTIVE, EREMOTEIO);
|
||||
}
|
||||
|
||||
if (mmp_label)
|
||||
nvlist_free(mmp_label);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load an existing storage pool, using the pool's builtin spa_config as a
|
||||
* source of configuration information.
|
||||
@@ -2343,6 +2548,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
|
||||
int parse, i;
|
||||
uint64_t obj;
|
||||
boolean_t missing_feat_write = B_FALSE;
|
||||
boolean_t activity_check = B_FALSE;
|
||||
nvlist_t *mos_config;
|
||||
|
||||
/*
|
||||
@@ -2440,6 +2646,33 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
|
||||
return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, ENXIO));
|
||||
}
|
||||
|
||||
/*
|
||||
* For pools which have the multihost property on determine if the
|
||||
* 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);
|
||||
if (activity_check) {
|
||||
error = spa_activity_check(spa, ub, config);
|
||||
if (error) {
|
||||
nvlist_free(label);
|
||||
return (error);
|
||||
}
|
||||
|
||||
if (ub->ub_mmp_magic == MMP_MAGIC && ub->ub_mmp_delay &&
|
||||
spa_get_hostid() == 0) {
|
||||
nvlist_free(label);
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_STATE, MMP_STATE_NO_HOSTID);
|
||||
return (spa_vdev_err(rvd, VDEV_AUX_ACTIVE, EREMOTEIO));
|
||||
}
|
||||
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_STATE, MMP_STATE_INACTIVE);
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_TXG, ub->ub_txg);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the pool has an unsupported version we can't open it.
|
||||
*/
|
||||
@@ -2667,24 +2900,9 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
|
||||
VERIFY(nvlist_lookup_string(nvconfig,
|
||||
ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
|
||||
|
||||
#ifdef _KERNEL
|
||||
myhostid = zone_get_hostid(NULL);
|
||||
#else /* _KERNEL */
|
||||
/*
|
||||
* We're emulating the system's hostid in userland, so
|
||||
* we can't use zone_get_hostid().
|
||||
*/
|
||||
(void) ddi_strtoul(hw_serial, NULL, 10, &myhostid);
|
||||
#endif /* _KERNEL */
|
||||
if (hostid != 0 && myhostid != 0 &&
|
||||
hostid != myhostid) {
|
||||
myhostid = spa_get_hostid();
|
||||
if (hostid && myhostid && hostid != myhostid) {
|
||||
nvlist_free(nvconfig);
|
||||
cmn_err(CE_WARN, "pool '%s' could not be "
|
||||
"loaded as it was last accessed by another "
|
||||
"system (host: %s hostid: 0x%lx). See: "
|
||||
"http://zfsonlinux.org/msg/ZFS-8000-EY",
|
||||
spa_name(spa), hostname,
|
||||
(unsigned long)hostid);
|
||||
return (SET_ERROR(EBADF));
|
||||
}
|
||||
}
|
||||
@@ -2850,12 +3068,25 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
|
||||
spa_prop_find(spa, ZPOOL_PROP_DELEGATION, &spa->spa_delegation);
|
||||
spa_prop_find(spa, ZPOOL_PROP_FAILUREMODE, &spa->spa_failmode);
|
||||
spa_prop_find(spa, ZPOOL_PROP_AUTOEXPAND, &spa->spa_autoexpand);
|
||||
spa_prop_find(spa, ZPOOL_PROP_MULTIHOST, &spa->spa_multihost);
|
||||
spa_prop_find(spa, ZPOOL_PROP_DEDUPDITTO,
|
||||
&spa->spa_dedup_ditto);
|
||||
|
||||
spa->spa_autoreplace = (autoreplace != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the 'multihost' property is set, then never allow a pool to
|
||||
* be imported when the system hostid is zero. The exception to
|
||||
* this rule is zdb which is always allowed to access pools.
|
||||
*/
|
||||
if (spa_multihost(spa) && spa_get_hostid() == 0 &&
|
||||
(spa->spa_import_flags & ZFS_IMPORT_SKIP_MMP) == 0) {
|
||||
fnvlist_add_uint64(spa->spa_load_info,
|
||||
ZPOOL_CONFIG_MMP_STATE, MMP_STATE_NO_HOSTID);
|
||||
return (spa_vdev_err(rvd, VDEV_AUX_ACTIVE, EREMOTEIO));
|
||||
}
|
||||
|
||||
/*
|
||||
* If the 'autoreplace' property is set, then post a resource notifying
|
||||
* the ZFS DE that it should not issue any faults for unopenable
|
||||
@@ -2980,6 +3211,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config,
|
||||
spa_set_log_state(spa, SPA_LOG_GOOD);
|
||||
spa->spa_sync_on = B_TRUE;
|
||||
txg_sync_start(spa->spa_dsl_pool);
|
||||
mmp_thread_start(spa);
|
||||
|
||||
/*
|
||||
* Wait for all claims to sync. We sync up to the highest
|
||||
@@ -3632,18 +3864,6 @@ spa_validate_aux_devs(spa_t *spa, nvlist_t *nvroot, uint64_t crtxg, int mode,
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* The L2ARC currently only supports disk devices in
|
||||
* kernel context. For user-level testing, we allow it.
|
||||
*/
|
||||
#ifdef _KERNEL
|
||||
if ((strcmp(config, ZPOOL_CONFIG_L2CACHE) == 0) &&
|
||||
strcmp(vd->vdev_ops->vdev_op_type, VDEV_TYPE_DISK) != 0) {
|
||||
error = SET_ERROR(ENOTBLK);
|
||||
vdev_free(vd);
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
vd->vdev_top = vd;
|
||||
|
||||
if ((error = vdev_open(vd)) == 0 &&
|
||||
@@ -3986,6 +4206,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION);
|
||||
spa->spa_failmode = zpool_prop_default_numeric(ZPOOL_PROP_FAILUREMODE);
|
||||
spa->spa_autoexpand = zpool_prop_default_numeric(ZPOOL_PROP_AUTOEXPAND);
|
||||
spa->spa_multihost = zpool_prop_default_numeric(ZPOOL_PROP_MULTIHOST);
|
||||
|
||||
if (props != NULL) {
|
||||
spa_configfile_set(spa, props, B_FALSE);
|
||||
@@ -3996,6 +4217,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
|
||||
spa->spa_sync_on = B_TRUE;
|
||||
txg_sync_start(spa->spa_dsl_pool);
|
||||
mmp_thread_start(spa);
|
||||
|
||||
/*
|
||||
* We explicitly wait for the first transaction to complete so that our
|
||||
@@ -6405,6 +6627,9 @@ spa_sync_props(void *arg, dmu_tx_t *tx)
|
||||
spa_async_request(spa,
|
||||
SPA_ASYNC_AUTOEXPAND);
|
||||
break;
|
||||
case ZPOOL_PROP_MULTIHOST:
|
||||
spa->spa_multihost = intval;
|
||||
break;
|
||||
case ZPOOL_PROP_DEDUPDITTO:
|
||||
spa->spa_dedup_ditto = intval;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user