svn commit: r354386 - vendor-sys/illumos/dist/uts/common/fs/zfs vendor-sys/illumos/dist/uts/common/fs/zfs/sys vendor-sys/illumos/dist/uts/common/sys/fs vendor/illumos/dist/cmd/zdb
Andriy Gapon
avg at FreeBSD.org
Wed Nov 6 09:09:04 UTC 2019
Author: avg
Date: Wed Nov 6 09:09:03 2019
New Revision: 354386
URL: https://svnweb.freebsd.org/changeset/base/354386
Log:
11770 additional mmp fixes
illumos/illumos-gate at 4348eb901228d2f8fa50bb132a34248e8662074e
https://github.com/illumos/illumos-gate/commit/4348eb901228d2f8fa50bb132a34248e8662074e
https://www.illumos.org/issues/11770
Port a few additional MMP fixes from ZoL that came in after our
initial MMP port.
4ca457b065 ZTS: Fix mmp_interval failure
ca95f70dff zpool import progress kstat
(only minimal changes from above can be pulled in right now)
060f0226e6 MMP interval and fail_intervals in uberblock
Portions contributed by: Jerry Jelinek <jerry.jelinek at joyent.com>
Portions contributed by: Brian Behlendorf <behlendorf1 at llnl.gov>
Author: Olaf Faaland <faaland1 at llnl.gov>
Modified:
vendor-sys/illumos/dist/uts/common/fs/zfs/mmp.c
vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c
vendor-sys/illumos/dist/uts/common/fs/zfs/sys/mmp.h
vendor-sys/illumos/dist/uts/common/fs/zfs/sys/uberblock_impl.h
vendor-sys/illumos/dist/uts/common/fs/zfs/uberblock.c
vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_label.c
vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h
Changes in other areas also in this revision:
Modified:
vendor/illumos/dist/cmd/zdb/zdb.c
Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/mmp.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/mmp.c Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/mmp.c Wed Nov 6 09:09:03 2019 (r354386)
@@ -50,40 +50,101 @@
* Uberblocks written by the txg_sync thread always go into the first
* (N-MMP_BLOCKS_PER_LABEL) slots, the remaining slots are reserved for MMP.
* They are used to hold uberblocks which are exactly the same as the last
- * synced uberblock except that the ub_timestamp is frequently updated.
- * Like all other uberblocks, the slot is written with an embedded checksum,
- * and slots with invalid checksums are ignored. This provides the
+ * synced uberblock except that the ub_timestamp and mmp_config are frequently
+ * updated. Like all other uberblocks, the slot is written with an embedded
+ * checksum, and slots with invalid checksums are ignored. This provides the
* "heartbeat", with no risk of overwriting good uberblocks that must be
* preserved, e.g. previous txgs and associated block pointers.
*
- * Two optional fields are added to uberblock structure: ub_mmp_magic and
- * ub_mmp_delay. The magic field allows zfs to tell whether ub_mmp_delay is
- * valid. The delay field is a decaying average of the amount of time between
- * completion of successive MMP writes, in nanoseconds. It is used to predict
- * how long the import must wait to detect activity in the pool, before
- * concluding it is not in use.
+ * Three optional fields are added to uberblock structure; ub_mmp_magic,
+ * ub_mmp_config, and ub_mmp_delay. The ub_mmp_magic value allows zfs to tell
+ * whether the other ub_mmp_* fields are valid. The ub_mmp_config field tells
+ * the importing host the settings of zfs_multihost_interval and
+ * zfs_multihost_fail_intervals on the host which last had (or currently has)
+ * the pool imported. These determine how long a host must wait to detect
+ * activity in the pool, before concluding the pool is not in use. The
+ * mmp_delay field is a decaying average of the amount of time between
+ * completion of successive MMP writes, in nanoseconds. It indicates whether
+ * MMP is enabled.
*
* During import an activity test may now be performed to determine if
* the pool is in use. The activity test is typically required if the
* ZPOOL_CONFIG_HOSTID does not match the system hostid, the pool state is
* POOL_STATE_ACTIVE, and the pool is not a root pool.
*
- * The activity test finds the "best" uberblock (highest txg & timestamp),
- * waits some time, and then finds the "best" uberblock again. If the txg
- * and timestamp in both "best" uberblocks do not match, the pool is in use
- * by another host and the import fails. Since the granularity of the
- * timestamp is in seconds this activity test must take a bare minimum of one
- * second. In order to assure the accuracy of the activity test, the default
- * values result in an activity test duration of 10x the mmp write interval.
+ * The activity test finds the "best" uberblock (highest txg, timestamp, and, if
+ * ub_mmp_magic is valid, sequence number from ub_mmp_config). It then waits
+ * some time, and finds the "best" uberblock again. If any of the mentioned
+ * fields have different values in the newly read uberblock, the pool is in use
+ * by another host and the import fails. In order to assure the accuracy of the
+ * activity test, the default values result in an activity test duration of 20x
+ * the mmp write interval.
*
- * The "zpool import" activity test can be expected to take a minimum time of
- * zfs_multihost_import_intervals * zfs_multihost_interval milliseconds. If the
- * "best" uberblock has a valid ub_mmp_delay field, then the duration of the
- * test may take longer if MMP writes were occurring less frequently than
- * expected. Additionally, the duration is then extended by a random 25% to
- * attempt to to detect simultaneous imports. For example, if both partner
- * hosts are rebooted at the same time and automatically attempt to import the
- * pool.
+ * The duration of the "zpool import" activity test depends on the information
+ * available in the "best" uberblock:
+ *
+ * 1) If uberblock was written by zfs-0.8 or newer and fail_intervals > 0:
+ * ub_mmp_config.fail_intervals * ub_mmp_config.multihost_interval * 2
+ *
+ * In this case, a weak guarantee is provided. Since the host which last had
+ * the pool imported will suspend the pool if no mmp writes land within
+ * fail_intervals * multihost_interval ms, the absence of writes during that
+ * time means either the pool is not imported, or it is imported but the pool
+ * is suspended and no further writes will occur.
+ *
+ * Note that resuming the suspended pool on the remote host would invalidate
+ * this guarantee, and so it is not allowed.
+ *
+ * The factor of 2 provides a conservative safety factor and derives from
+ * MMP_IMPORT_SAFETY_FACTOR;
+ *
+ * 2) If uberblock was written by zfs-0.8 or newer and fail_intervals == 0:
+ * (ub_mmp_config.multihost_interval + ub_mmp_delay) *
+ * zfs_multihost_import_intervals
+ *
+ * In this case no guarantee can provided. However, as long as some devices
+ * are healthy and connected, it is likely that at least one write will land
+ * within (multihost_interval + mmp_delay) because multihost_interval is
+ * enough time for a write to be attempted to each leaf vdev, and mmp_delay
+ * is enough for one to land, based on past delays. Multiplying by
+ * zfs_multihost_import_intervals provides a conservative safety factor.
+ *
+ * 3) If uberblock was written by zfs-0.7:
+ * (zfs_multihost_interval + ub_mmp_delay) * zfs_multihost_import_intervals
+ *
+ * The same logic as case #2 applies, but we do not know remote tunables.
+ *
+ * We use the local value for zfs_multihost_interval because the original MMP
+ * did not record this value in the uberblock.
+ *
+ * ub_mmp_delay >= (zfs_multihost_interval / leaves), so if the other host
+ * has a much larger zfs_multihost_interval set, ub_mmp_delay will reflect
+ * that. We will have waited enough time for zfs_multihost_import_intervals
+ * writes to be issued and all but one to land.
+ *
+ * single device pool example delays
+ *
+ * import_delay = (1 + 1) * 20 = 40s #defaults, no I/O delay
+ * import_delay = (1 + 10) * 20 = 220s #defaults, 10s I/O delay
+ * import_delay = (10 + 10) * 20 = 400s #10s multihost_interval,
+ * no I/O delay
+ * 100 device pool example delays
+ *
+ * import_delay = (1 + .01) * 20 = 20s #defaults, no I/O delay
+ * import_delay = (1 + 10) * 20 = 220s #defaults, 10s I/O delay
+ * import_delay = (10 + .1) * 20 = 202s #10s multihost_interval,
+ * no I/O delay
+ *
+ * 4) Otherwise, this uberblock was written by a pre-MMP zfs:
+ * zfs_multihost_import_intervals * zfs_multihost_interval
+ *
+ * In this case local tunables are used. By default this product = 10s, long
+ * enough for a pool with any activity at all to write at least one
+ * uberblock. No guarantee can be provided.
+ *
+ * Additionally, the duration is then extended by a random 25% to attempt to to
+ * detect simultaneous imports. For example, if both partner hosts are rebooted
+ * at the same time and automatically attempt to import the pool.
*/
/*
@@ -91,10 +152,9 @@
* 'multihost' pool property is on. This is one factor used to determine the
* length of the activity check during import.
*
- * The mmp write period is zfs_multihost_interval / leaf-vdevs milliseconds.
- * This means that on average an mmp write will be issued for each leaf vdev
- * every zfs_multihost_interval milliseconds. In practice, the observed period
- * can vary with the I/O load and this observed value is the delay which is
+ * On average an mmp write will be issued for each leaf vdev every
+ * zfs_multihost_interval milliseconds. In practice, the observed period can
+ * vary with the I/O load and this observed value is the ub_mmp_delay which is
* stored in the uberblock. The minimum allowed value is 100 ms.
*/
ulong_t zfs_multihost_interval = MMP_DEFAULT_INTERVAL;
@@ -109,19 +169,21 @@ ulong_t zfs_multihost_interval = MMP_DEFAULT_INTERVAL;
uint_t zfs_multihost_import_intervals = MMP_DEFAULT_IMPORT_INTERVALS;
/*
- * Controls the behavior of the pool when mmp write failures are detected.
+ * Controls the behavior of the pool when mmp write failures or delays are
+ * detected.
*
- * When zfs_multihost_fail_intervals = 0 then mmp write failures are ignored.
- * The failures will still be reported to the ZED which depending on its
- * configuration may take action such as suspending the pool or taking a
+ * When zfs_multihost_fail_intervals = 0, mmp write failures or delays are
+ * ignored. The failures will still be reported to the ZED which depending on
+ * its configuration may take action such as suspending the pool or taking a
* device offline.
*
- * When zfs_multihost_fail_intervals > 0 then sequential mmp write failures will
- * cause the pool to be suspended. This occurs when
- * zfs_multihost_fail_intervals * zfs_multihost_interval milliseconds have
- * passed since the last successful mmp write. This guarantees the activity
- * test will see mmp writes if the
- * pool is imported.
+ * When zfs_multihost_fail_intervals > 0, the pool will be suspended if
+ * zfs_multihost_fail_intervals * zfs_multihost_interval milliseconds pass
+ * without a successful mmp write. This guarantees the activity test will see
+ * mmp writes if the pool is imported. A value of 1 is ignored and treated as
+ * if it was set to 2, because a single leaf vdev pool will issue a write once
+ * per multihost_interval and thus any variation in latency would cause the
+ * pool to be suspended.
*/
uint_t zfs_multihost_fail_intervals = MMP_DEFAULT_FAIL_INTERVALS;
@@ -137,6 +199,14 @@ mmp_init(spa_t *spa)
cv_init(&mmp->mmp_thread_cv, NULL, CV_DEFAULT, NULL);
mutex_init(&mmp->mmp_io_lock, NULL, MUTEX_DEFAULT, NULL);
mmp->mmp_kstat_id = 1;
+
+ /*
+ * mmp_write_done() calculates mmp_delay based on prior mmp_delay and
+ * the elapsed time since the last write. For the first mmp write,
+ * there is no "last write", so we start with fake non-zero values.
+ */
+ mmp->mmp_last_write = gethrtime();
+ mmp->mmp_delay = MSEC2NSEC(MMP_INTERVAL_OK(zfs_multihost_interval));
}
void
@@ -174,10 +244,10 @@ mmp_thread_start(spa_t *spa)
if (spa_writeable(spa)) {
mutex_enter(&mmp->mmp_thread_lock);
if (!mmp->mmp_thread) {
- dprintf("mmp_thread_start pool %s\n",
- spa->spa_name);
mmp->mmp_thread = thread_create(NULL, 0, mmp_thread,
spa, 0, &p0, TS_RUN, minclsyspri);
+ zfs_dbgmsg("MMP thread started pool '%s' "
+ "gethrtime %llu", spa_name(spa), gethrtime());
}
mutex_exit(&mmp->mmp_thread_lock);
}
@@ -196,6 +266,8 @@ mmp_thread_stop(spa_t *spa)
cv_wait(&mmp->mmp_thread_cv, &mmp->mmp_thread_lock);
}
mutex_exit(&mmp->mmp_thread_lock);
+ zfs_dbgmsg("MMP thread stopped pool '%s' gethrtime %llu",
+ spa_name(spa), gethrtime());
ASSERT(mmp->mmp_thread == NULL);
mmp->mmp_thread_exiting = 0;
@@ -305,7 +377,8 @@ mmp_delay_update(spa_t *spa, boolean_t write_completed
* strictly less than, in case delay was changed above.
*/
if (delay < mts->mmp_delay) {
- hrtime_t min_delay = MSEC2NSEC(zfs_multihost_interval) /
+ hrtime_t min_delay =
+ MSEC2NSEC(MMP_INTERVAL_OK(zfs_multihost_interval)) /
MAX(1, vdev_count_leaves(spa));
mts->mmp_delay = MAX(((delay + mts->mmp_delay * 127) / 128),
min_delay);
@@ -346,6 +419,7 @@ mmp_update_uberblock(spa_t *spa, uberblock_t *ub)
mutex_enter(&mmp->mmp_io_lock);
mmp->mmp_ub = *ub;
+ mmp->mmp_seq = 1;
mmp->mmp_ub.ub_timestamp = gethrestime_sec();
mmp_delay_update(spa, B_TRUE);
mutex_exit(&mmp->mmp_io_lock);
@@ -370,8 +444,9 @@ mmp_write_uberblock(spa_t *spa)
spa_config_enter(spa, SCL_STATE, mmp_tag, RW_READER);
lock_acquire_time = gethrtime() - lock_acquire_time;
if (lock_acquire_time > (MSEC2NSEC(MMP_MIN_INTERVAL) / 10))
- zfs_dbgmsg("SCL_STATE acquisition took %llu ns\n",
- (u_longlong_t)lock_acquire_time);
+ zfs_dbgmsg("MMP SCL_STATE acquisition pool '%s' took %llu ns "
+ "gethrtime %llu", spa_name(spa), lock_acquire_time,
+ gethrtime());
mutex_enter(&mmp->mmp_io_lock);
@@ -400,6 +475,9 @@ mmp_write_uberblock(spa_t *spa)
* gethrestime_sec(), mmp->mmp_delay, NULL, 0,
* mmp->mmp_kstat_id++, error);
*/
+ zfs_dbgmsg("MMP error choosing leaf pool '%s' "
+ "gethrtime %llu fail_mask %#x", spa_name(spa),
+ gethrtime(), error);
}
mutex_exit(&mmp->mmp_io_lock);
spa_config_exit(spa, SCL_STATE, mmp_tag);
@@ -407,16 +485,34 @@ mmp_write_uberblock(spa_t *spa)
}
vd = spa->spa_mmp.mmp_last_leaf;
- mmp->mmp_skip_error = 0;
+ if (mmp->mmp_skip_error != 0) {
+ mmp->mmp_skip_error = 0;
+ zfs_dbgmsg("MMP write after skipping due to unavailable "
+ "leaves, pool '%s' gethrtime %llu leaf %#llu",
+ spa_name(spa), gethrtime(), vd->vdev_guid);
+ }
if (mmp->mmp_zio_root == NULL)
mmp->mmp_zio_root = zio_root(spa, NULL, NULL,
flags | ZIO_FLAG_GODFATHER);
+ if (mmp->mmp_ub.ub_timestamp != gethrestime_sec()) {
+ /*
+ * Want to reset mmp_seq when timestamp advances because after
+ * an mmp_seq wrap new values will not be chosen by
+ * uberblock_compare() as the "best".
+ */
+ mmp->mmp_ub.ub_timestamp = gethrestime_sec();
+ mmp->mmp_seq = 1;
+ }
+
ub = &mmp->mmp_ub;
- ub->ub_timestamp = gethrestime_sec();
ub->ub_mmp_magic = MMP_MAGIC;
ub->ub_mmp_delay = mmp->mmp_delay;
+ ub->ub_mmp_config = MMP_SEQ_SET(mmp->mmp_seq) |
+ MMP_INTERVAL_SET(MMP_INTERVAL_OK(zfs_multihost_interval)) |
+ MMP_FAIL_INT_SET(MMP_FAIL_INTVS_OK(
+ zfs_multihost_fail_intervals));
vd->vdev_mmp_pending = gethrtime();
vd->vdev_mmp_kstat_id = mmp->mmp_kstat_id;
@@ -425,6 +521,7 @@ mmp_write_uberblock(spa_t *spa)
abd_zero(ub_abd, VDEV_UBERBLOCK_SIZE(vd));
abd_copy_from_buf(ub_abd, ub, sizeof (uberblock_t));
+ mmp->mmp_seq++;
mmp->mmp_kstat_id++;
mutex_exit(&mmp->mmp_io_lock);
@@ -450,39 +547,76 @@ mmp_thread(void *arg)
{
spa_t *spa = (spa_t *)arg;
mmp_thread_t *mmp = &spa->spa_mmp;
- boolean_t last_spa_suspended = spa_suspended(spa);
- boolean_t last_spa_multihost = spa_multihost(spa);
+ boolean_t suspended = spa_suspended(spa);
+ boolean_t multihost = spa_multihost(spa);
+ uint64_t mmp_interval = MSEC2NSEC(MMP_INTERVAL_OK(
+ zfs_multihost_interval));
+ uint32_t mmp_fail_intervals = MMP_FAIL_INTVS_OK(
+ zfs_multihost_fail_intervals);
+ hrtime_t mmp_fail_ns = mmp_fail_intervals * mmp_interval;
+ boolean_t last_spa_suspended = suspended;
+ boolean_t last_spa_multihost = multihost;
+ uint64_t last_mmp_interval = mmp_interval;
+ uint32_t last_mmp_fail_intervals = mmp_fail_intervals;
+ hrtime_t last_mmp_fail_ns = mmp_fail_ns;
callb_cpr_t cpr;
- hrtime_t max_fail_ns = zfs_multihost_fail_intervals *
- MSEC2NSEC(MAX(zfs_multihost_interval, MMP_MIN_INTERVAL));
+ int skip_wait = 0;
mmp_thread_enter(mmp, &cpr);
- /*
- * The mmp_write_done() function calculates mmp_delay based on the
- * prior value of mmp_delay and the elapsed time since the last write.
- * For the first mmp write, there is no "last write", so we start
- * with fake, but reasonable, default non-zero values.
- */
- mmp->mmp_delay = MSEC2NSEC(MAX(zfs_multihost_interval,
- MMP_MIN_INTERVAL)) / MAX(vdev_count_leaves(spa), 1);
- mmp->mmp_last_write = gethrtime() - mmp->mmp_delay;
-
while (!mmp->mmp_thread_exiting) {
- uint64_t mmp_fail_intervals = zfs_multihost_fail_intervals;
- uint64_t mmp_interval = MSEC2NSEC(
- MAX(zfs_multihost_interval, MMP_MIN_INTERVAL));
- boolean_t suspended = spa_suspended(spa);
- boolean_t multihost = spa_multihost(spa);
- hrtime_t next_time;
+ hrtime_t next_time = gethrtime() +
+ MSEC2NSEC(MMP_DEFAULT_INTERVAL);
+ int leaves = MAX(vdev_count_leaves(spa), 1);
+ /* Detect changes in tunables or state */
+
+ last_spa_suspended = suspended;
+ last_spa_multihost = multihost;
+ suspended = spa_suspended(spa);
+ multihost = spa_multihost(spa);
+
+ last_mmp_interval = mmp_interval;
+ last_mmp_fail_intervals = mmp_fail_intervals;
+ last_mmp_fail_ns = mmp_fail_ns;
+ mmp_interval = MSEC2NSEC(MMP_INTERVAL_OK(
+ zfs_multihost_interval));
+ mmp_fail_intervals = MMP_FAIL_INTVS_OK(
+ zfs_multihost_fail_intervals);
+
+ /* Smooth so pool is not suspended when reducing tunables */
+ if (mmp_fail_intervals * mmp_interval < mmp_fail_ns) {
+ mmp_fail_ns = (mmp_fail_ns * 31 +
+ mmp_fail_intervals * mmp_interval) / 32;
+ } else {
+ mmp_fail_ns = mmp_fail_intervals *
+ mmp_interval;
+ }
+
+ if (mmp_interval != last_mmp_interval ||
+ mmp_fail_intervals != last_mmp_fail_intervals) {
+ /*
+ * We want other hosts to see new tunables as quickly as
+ * possible. Write out at higher frequency than usual.
+ */
+ skip_wait += leaves;
+ }
+
if (multihost)
- next_time = gethrtime() + mmp_interval /
- MAX(vdev_count_leaves(spa), 1);
- else
- next_time = gethrtime() +
- MSEC2NSEC(MMP_DEFAULT_INTERVAL);
+ next_time = gethrtime() + mmp_interval / leaves;
+ if (mmp_fail_ns != last_mmp_fail_ns) {
+ zfs_dbgmsg("MMP interval change pool '%s' "
+ "gethrtime %llu last_mmp_interval %llu "
+ "mmp_interval %llu last_mmp_fail_intervals %u "
+ "mmp_fail_intervals %u mmp_fail_ns %llu "
+ "skip_wait %d leaves %d next_time %llu",
+ spa_name(spa), gethrtime(), last_mmp_interval,
+ mmp_interval, last_mmp_fail_intervals,
+ mmp_fail_intervals, mmp_fail_ns, skip_wait, leaves,
+ next_time);
+ }
+
/*
* MMP off => on, or suspended => !suspended:
* No writes occurred recently. Update mmp_last_write to give
@@ -490,8 +624,14 @@ mmp_thread(void *arg)
*/
if ((!last_spa_multihost && multihost) ||
(last_spa_suspended && !suspended)) {
+ zfs_dbgmsg("MMP state change pool '%s': gethrtime %llu "
+ "last_spa_multihost %u multihost %u "
+ "last_spa_suspended %u suspended %u",
+ spa_name(spa), last_spa_multihost, multihost,
+ last_spa_suspended, suspended);
mutex_enter(&mmp->mmp_io_lock);
mmp->mmp_last_write = gethrtime();
+ mmp->mmp_delay = mmp_interval;
mutex_exit(&mmp->mmp_io_lock);
}
@@ -504,37 +644,38 @@ mmp_thread(void *arg)
mmp->mmp_delay = 0;
mutex_exit(&mmp->mmp_io_lock);
}
- last_spa_multihost = multihost;
- last_spa_suspended = suspended;
/*
- * Smooth max_fail_ns when its factors are decreased, because
- * making (max_fail_ns < mmp_interval) results in the pool being
- * immediately suspended before writes can occur at the new
- * higher frequency.
- */
- if ((mmp_interval * mmp_fail_intervals) < max_fail_ns) {
- max_fail_ns = ((31 * max_fail_ns) + (mmp_interval *
- mmp_fail_intervals)) / 32;
- } else {
- max_fail_ns = mmp_interval * mmp_fail_intervals;
- }
-
- /*
* Suspend the pool if no MMP write has succeeded in over
* mmp_interval * mmp_fail_intervals nanoseconds.
*/
- if (!suspended && mmp_fail_intervals && multihost &&
- (gethrtime() - mmp->mmp_last_write) > max_fail_ns) {
+ if (multihost && !suspended && mmp_fail_intervals &&
+ (gethrtime() - mmp->mmp_last_write) > mmp_fail_ns) {
+ zfs_dbgmsg("MMP suspending pool '%s': gethrtime %llu "
+ "mmp_last_write %llu mmp_interval %llu "
+ "mmp_fail_intervals %llu mmp_fail_ns %llu",
+ spa_name(spa), (u_longlong_t)gethrtime(),
+ (u_longlong_t)mmp->mmp_last_write,
+ (u_longlong_t)mmp_interval,
+ (u_longlong_t)mmp_fail_intervals,
+ (u_longlong_t)mmp_fail_ns);
cmn_err(CE_WARN, "MMP writes to pool '%s' have not "
- "succeeded in over %llus; suspending pool",
+ "succeeded in over %llu ms; suspending pool. "
+ "Hrtime %llu",
spa_name(spa),
- NSEC2SEC(gethrtime() - mmp->mmp_last_write));
+ NSEC2MSEC(gethrtime() - mmp->mmp_last_write),
+ gethrtime());
zio_suspend(spa, NULL, ZIO_SUSPEND_MMP);
}
if (multihost && !suspended)
mmp_write_uberblock(spa);
+
+ if (skip_wait > 0) {
+ next_time = gethrtime() + MSEC2NSEC(MMP_MIN_INTERVAL) /
+ leaves;
+ skip_wait--;
+ }
CALLB_CPR_SAFE_BEGIN(&cpr);
(void) cv_timedwait_sig_hrtime(&mmp->mmp_thread_cv,
Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/spa.c Wed Nov 6 09:09:03 2019 (r354386)
@@ -2338,6 +2338,7 @@ spa_activity_check_required(spa_t *spa, uberblock_t *u
uint64_t hostid = 0;
uint64_t tryconfig_txg = 0;
uint64_t tryconfig_timestamp = 0;
+ uint16_t tryconfig_mmp_seq = 0;
nvlist_t *nvinfo;
if (nvlist_exists(config, ZPOOL_CONFIG_LOAD_INFO)) {
@@ -2346,6 +2347,8 @@ spa_activity_check_required(spa_t *spa, uberblock_t *u
&tryconfig_txg);
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_TIMESTAMP,
&tryconfig_timestamp);
+ (void) nvlist_lookup_uint16(nvinfo, ZPOOL_CONFIG_MMP_SEQ,
+ &tryconfig_mmp_seq);
}
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE, &state);
@@ -2362,14 +2365,17 @@ spa_activity_check_required(spa_t *spa, uberblock_t *u
*/
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 the tryconfig_ values are nonzero, they are the results of an
+ * earlier tryimport. If they all 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)
+ tryconfig_timestamp && tryconfig_timestamp == ub->ub_timestamp &&
+ tryconfig_mmp_seq && tryconfig_mmp_seq ==
+ (MMP_SEQ_VALID(ub) ? MMP_SEQ(ub) : 0))
return (B_FALSE);
/*
@@ -2393,16 +2399,87 @@ spa_activity_check_required(spa_t *spa, uberblock_t *u
}
/*
+ * Nanoseconds the activity check must watch for changes on-disk.
+ */
+static uint64_t
+spa_activity_check_duration(spa_t *spa, uberblock_t *ub)
+{
+ uint64_t import_intervals = MAX(zfs_multihost_import_intervals, 1);
+ uint64_t multihost_interval = MSEC2NSEC(
+ MMP_INTERVAL_OK(zfs_multihost_interval));
+ uint64_t import_delay = MAX(NANOSEC, import_intervals *
+ multihost_interval);
+
+ /*
+ * Local tunables determine a minimum duration except for the case
+ * where we know when the remote host will suspend the pool if MMP
+ * writes do not land.
+ *
+ * See Big Theory comment at the top of mmp.c for the reasoning behind
+ * these cases and times.
+ */
+
+ ASSERT(MMP_IMPORT_SAFETY_FACTOR >= 100);
+
+ if (MMP_INTERVAL_VALID(ub) && MMP_FAIL_INT_VALID(ub) &&
+ MMP_FAIL_INT(ub) > 0) {
+
+ /* MMP on remote host will suspend pool after failed writes */
+ import_delay = MMP_FAIL_INT(ub) * MSEC2NSEC(MMP_INTERVAL(ub)) *
+ MMP_IMPORT_SAFETY_FACTOR / 100;
+
+ zfs_dbgmsg("fail_intvals>0 import_delay=%llu ub_mmp "
+ "mmp_fails=%llu ub_mmp mmp_interval=%llu "
+ "import_intervals=%u", import_delay, MMP_FAIL_INT(ub),
+ MMP_INTERVAL(ub), import_intervals);
+
+ } else if (MMP_INTERVAL_VALID(ub) && MMP_FAIL_INT_VALID(ub) &&
+ MMP_FAIL_INT(ub) == 0) {
+
+ /* MMP on remote host will never suspend pool */
+ import_delay = MAX(import_delay, (MSEC2NSEC(MMP_INTERVAL(ub)) +
+ ub->ub_mmp_delay) * import_intervals);
+
+ zfs_dbgmsg("fail_intvals=0 import_delay=%llu ub_mmp "
+ "mmp_interval=%llu ub_mmp_delay=%llu "
+ "import_intervals=%u", import_delay, MMP_INTERVAL(ub),
+ ub->ub_mmp_delay, import_intervals);
+
+ } else if (MMP_VALID(ub)) {
+ /*
+ * zfs-0.7 compatability case
+ */
+
+ import_delay = MAX(import_delay, (multihost_interval +
+ ub->ub_mmp_delay) * import_intervals);
+
+ zfs_dbgmsg("import_delay=%llu ub_mmp_delay=%llu "
+ "import_intervals=%u leaves=%u", import_delay,
+ ub->ub_mmp_delay, import_intervals,
+ vdev_count_leaves(spa));
+ } else {
+ /* Using local tunings is the only reasonable option */
+ zfs_dbgmsg("pool last imported on non-MMP aware "
+ "host using import_delay=%llu multihost_interval=%llu "
+ "import_intervals=%u", import_delay, multihost_interval,
+ import_intervals);
+ }
+
+ return (import_delay);
+}
+
+/*
* 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;
+ uint64_t mmp_config = ub->ub_mmp_config;
+ uint16_t mmp_seq = MMP_SEQ_VALID(ub) ? MMP_SEQ(ub) : 0;
+ uint64_t import_delay;
hrtime_t import_expire;
nvlist_t *mmp_label = NULL;
vdev_t *rvd = spa->spa_root_vdev;
@@ -2419,7 +2496,7 @@ spa_activity_check(spa_t *spa, uberblock_t *ub, nvlist
* 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
+ * Otherwise, the pool might be in use on another host. Check for
* changes in the uberblocks on disk if necessary.
*/
if (nvlist_exists(config, ZPOOL_CONFIG_LOAD_INFO)) {
@@ -2434,32 +2511,25 @@ spa_activity_check(spa_t *spa, uberblock_t *ub, nvlist
}
}
- /*
- * 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 * MAX(vdev_count_leaves(spa), 1));
+ import_delay = spa_activity_check_duration(spa, ub);
- /* Apply a floor using the local default values. */
- import_delay = MAX(import_delay, import_intervals *
- MSEC2NSEC(MAX(zfs_multihost_interval, MMP_MIN_INTERVAL)));
-
- zfs_dbgmsg("import_delay=%llu ub_mmp_delay=%llu import_intervals=%u "
- "leaves=%u", import_delay, ub->ub_mmp_delay, import_intervals,
- vdev_count_leaves(spa));
-
/* Add a small random factor in case of simultaneous imports (0-25%) */
- import_expire = gethrtime() + import_delay +
- (import_delay * spa_get_random(250) / 1000);
+ import_delay += import_delay * spa_get_random(250) / 1000;
+ import_expire = gethrtime() + import_delay;
+
while (gethrtime() < import_expire) {
vdev_uberblock_load(rvd, ub, &mmp_label);
- if (txg != ub->ub_txg || timestamp != ub->ub_timestamp) {
+ if (txg != ub->ub_txg || timestamp != ub->ub_timestamp ||
+ mmp_seq != (MMP_SEQ_VALID(ub) ? MMP_SEQ(ub) : 0)) {
+ zfs_dbgmsg("multihost activity detected "
+ "txg %llu ub_txg %llu "
+ "timestamp %llu ub_timestamp %llu "
+ "mmp_config %#llx ub_mmp_config %#llx",
+ txg, ub->ub_txg, timestamp, ub->ub_timestamp,
+ mmp_config, ub->ub_mmp_config);
+
error = SET_ERROR(EREMOTEIO);
break;
}
@@ -2844,6 +2914,9 @@ spa_ld_select_uberblock(spa_t *spa, spa_import_type_t
ZPOOL_CONFIG_MMP_STATE, MMP_STATE_INACTIVE);
fnvlist_add_uint64(spa->spa_load_info,
ZPOOL_CONFIG_MMP_TXG, ub->ub_txg);
+ fnvlist_add_uint16(spa->spa_load_info,
+ ZPOOL_CONFIG_MMP_SEQ,
+ (MMP_SEQ_VALID(ub) ? MMP_SEQ(ub) : 0));
}
/*
Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/sys/mmp.h
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/sys/mmp.h Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/sys/mmp.h Wed Nov 6 09:09:03 2019 (r354386)
@@ -29,8 +29,13 @@ extern "C" {
#define MMP_MIN_INTERVAL 100 /* ms */
#define MMP_DEFAULT_INTERVAL 1000 /* ms */
-#define MMP_DEFAULT_IMPORT_INTERVALS 10
-#define MMP_DEFAULT_FAIL_INTERVALS 5
+#define MMP_DEFAULT_IMPORT_INTERVALS 20
+#define MMP_DEFAULT_FAIL_INTERVALS 10
+#define MMP_MIN_FAIL_INTERVALS 2 /* min if != 0 */
+#define MMP_IMPORT_SAFETY_FACTOR 200 /* pct */
+#define MMP_INTERVAL_OK(interval) MAX(interval, MMP_MIN_INTERVAL)
+#define MMP_FAIL_INTVS_OK(fails) (fails == 0 ? 0 : MAX(fails, \
+ MMP_MIN_FAIL_INTERVALS))
typedef struct mmp_thread {
kmutex_t mmp_thread_lock; /* protect thread mgmt fields */
@@ -46,6 +51,7 @@ typedef struct mmp_thread {
int mmp_skip_error; /* reason for last skipped write */
vdev_t *mmp_last_leaf; /* last mmp write sent here */
uint64_t mmp_leaf_last_gen; /* last mmp write sent here */
+ uint32_t mmp_seq; /* intra-second update counter */
} mmp_thread_t;
Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/sys/uberblock_impl.h
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/sys/uberblock_impl.h Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/sys/uberblock_impl.h Wed Nov 6 09:09:03 2019 (r354386)
@@ -44,8 +44,37 @@ extern "C" {
*/
#define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */
#define UBERBLOCK_SHIFT 10 /* up to 1K */
-#define MMP_MAGIC 0xa11cea11 /* all-see-all */
+#define MMP_MAGIC 0xa11cea11 /* all-see-all */
+#define MMP_INTERVAL_VALID_BIT 0x01
+#define MMP_SEQ_VALID_BIT 0x02
+#define MMP_FAIL_INT_VALID_BIT 0x04
+
+#define MMP_VALID(ubp) (ubp->ub_magic == UBERBLOCK_MAGIC && \
+ ubp->ub_mmp_magic == MMP_MAGIC)
+#define MMP_INTERVAL_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \
+ MMP_INTERVAL_VALID_BIT))
+#define MMP_SEQ_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \
+ MMP_SEQ_VALID_BIT))
+#define MMP_FAIL_INT_VALID(ubp) (MMP_VALID(ubp) && (ubp->ub_mmp_config & \
+ MMP_FAIL_INT_VALID_BIT))
+
+#define MMP_INTERVAL(ubp) ((ubp->ub_mmp_config & 0x00000000FFFFFF00) \
+ >> 8)
+#define MMP_SEQ(ubp) ((ubp->ub_mmp_config & 0x0000FFFF00000000) \
+ >> 32)
+#define MMP_FAIL_INT(ubp) ((ubp->ub_mmp_config & 0xFFFF000000000000) \
+ >> 48)
+
+#define MMP_INTERVAL_SET(write) \
+ (((uint64_t)(write & 0xFFFFFF) << 8) | MMP_INTERVAL_VALID_BIT)
+
+#define MMP_SEQ_SET(seq) \
+ (((uint64_t)(seq & 0xFFFF) << 32) | MMP_SEQ_VALID_BIT)
+
+#define MMP_FAIL_INT_SET(fail) \
+ (((uint64_t)(fail & 0xFFFF) << 48) | MMP_FAIL_INT_VALID_BIT)
+
struct uberblock {
uint64_t ub_magic; /* UBERBLOCK_MAGIC */
uint64_t ub_version; /* SPA_VERSION */
@@ -59,8 +88,31 @@ struct uberblock {
/* Maybe missing in uberblocks we read, but always written */
uint64_t ub_mmp_magic;
+ /*
+ * If ub_mmp_delay == 0 and ub_mmp_magic is valid, MMP is off.
+ * Otherwise, nanosec since last MMP write.
+ */
uint64_t ub_mmp_delay;
- uint64_t ub_mmp_seq;
+
+ /*
+ * The ub_mmp_config contains the multihost write interval, multihost
+ * fail intervals, sequence number for sub-second granularity, and
+ * valid bit mask. This layout is as follows:
+ *
+ * 64 56 48 40 32 24 16 8 0
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 0 | Fail Intervals| Seq | Write Interval (ms) | VALID |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ *
+ * This allows a write_interval of (2^24/1000)s, over 4.5 hours
+ *
+ * VALID Bits:
+ * - 0x01 - Write Interval (ms)
+ * - 0x02 - Sequence number exists
+ * - 0x04 - Fail Intervals
+ * - 0xf8 - Reserved
+ */
+ uint64_t ub_mmp_config;
/*
* ub_checkpoint_txg indicates two things about the current uberblock:
Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/uberblock.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/uberblock.c Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/uberblock.c Wed Nov 6 09:09:03 2019 (r354386)
@@ -26,6 +26,7 @@
#include <sys/zfs_context.h>
#include <sys/uberblock_impl.h>
#include <sys/vdev_impl.h>
+#include <sys/mmp.h>
int
uberblock_verify(uberblock_t *ub)
@@ -58,8 +59,15 @@ uberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_
ub->ub_timestamp = gethrestime_sec();
ub->ub_software_version = SPA_VERSION;
ub->ub_mmp_magic = MMP_MAGIC;
- ub->ub_mmp_delay = spa_multihost(rvd->vdev_spa) ? mmp_delay : 0;
- ub->ub_mmp_seq = 0;
+ if (spa_multihost(rvd->vdev_spa)) {
+ ub->ub_mmp_delay = mmp_delay;
+ ub->ub_mmp_config = MMP_SEQ_SET(0) |
+ MMP_INTERVAL_SET(zfs_multihost_interval) |
+ MMP_FAIL_INT_SET(zfs_multihost_fail_intervals);
+ } else {
+ ub->ub_mmp_delay = 0;
+ ub->ub_mmp_config = 0;
+ }
ub->ub_checkpoint_txg = 0;
return (ub->ub_rootbp.blk_birth == txg);
Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_label.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_label.c Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/vdev_label.c Wed Nov 6 09:09:03 2019 (r354386)
@@ -1016,10 +1016,35 @@ static int
vdev_uberblock_compare(const uberblock_t *ub1, const uberblock_t *ub2)
{
int cmp = AVL_CMP(ub1->ub_txg, ub2->ub_txg);
+
if (likely(cmp))
return (cmp);
- return (AVL_CMP(ub1->ub_timestamp, ub2->ub_timestamp));
+ cmp = AVL_CMP(ub1->ub_timestamp, ub2->ub_timestamp);
+ if (likely(cmp))
+ return (cmp);
+
+ /*
+ * If MMP_VALID(ub) && MMP_SEQ_VALID(ub) then the host has an MMP-aware
+ * ZFS, e.g. zfsonlinux >= 0.7.
+ *
+ * If one ub has MMP and the other does not, they were written by
+ * different hosts, which matters for MMP. So we treat no MMP/no SEQ as
+ * a 0 value.
+ *
+ * Since timestamp and txg are the same if we get this far, either is
+ * acceptable for importing the pool.
+ */
+ unsigned int seq1 = 0;
+ unsigned int seq2 = 0;
+
+ if (MMP_VALID(ub1) && MMP_SEQ_VALID(ub1))
+ seq1 = MMP_SEQ(ub1);
+
+ if (MMP_VALID(ub2) && MMP_SEQ_VALID(ub2))
+ seq2 = MMP_SEQ(ub2);
+
+ return (AVL_CMP(seq1, seq2));
}
struct ubl_cbdata {
Modified: vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h
==============================================================================
--- vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h Wed Nov 6 09:05:39 2019 (r354385)
+++ vendor-sys/illumos/dist/uts/common/sys/fs/zfs.h Wed Nov 6 09:09:03 2019 (r354386)
@@ -600,6 +600,7 @@ typedef struct zpool_load_policy {
#define ZPOOL_CONFIG_CACHEFILE "cachefile" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_STATE "mmp_state" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_TXG "mmp_txg" /* not stored on disk */
+#define ZPOOL_CONFIG_MMP_SEQ "mmp_seq" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_HOSTNAME "mmp_hostname" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_HOSTID "mmp_hostid" /* not stored on disk */
#define ZPOOL_CONFIG_ALLOCATION_BIAS "alloc_bias" /* not stored on disk */
More information about the svn-src-vendor
mailing list