summaryrefslogtreecommitdiffstats
path: root/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c
diff options
context:
space:
mode:
authorsmh <smh@FreeBSD.org>2015-01-18 23:15:49 +0000
committersmh <smh@FreeBSD.org>2015-01-18 23:15:49 +0000
commit3d07512cea65fe9d6ebf2e47235c5d3b0577fbb5 (patch)
treef8f7e00ce7bd470c3fb3b130c942a90eb81f1d2f /sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c
parent51e92f331975b4ef1a007b05d3266697edab8381 (diff)
downloadFreeBSD-src-3d07512cea65fe9d6ebf2e47235c5d3b0577fbb5.zip
FreeBSD-src-3d07512cea65fe9d6ebf2e47235c5d3b0577fbb5.tar.gz
Clean ZFS spa config before syncing
A number of entries that can be present in the spa config shouldn't be saved to disk so add a method to ensure this is case. Without this if the last caller to vdev_config_generate requested stats then we can end up in the cache file. Also only skip a none writable pool in the cache file generation if its active. This prevents unavailable pools incorrectly getting removed from cache file. Tested by: delphij MFC after: 2 weeks Sponsored by: Multiplay
Diffstat (limited to 'sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c')
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c
index c4ee741..be1e528 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c
@@ -140,6 +140,26 @@ out:
kobj_close_file(file);
}
+static void
+spa_config_clean(nvlist_t *nvl)
+{
+ nvlist_t **child;
+ nvlist_t *nvroot = NULL;
+ uint_t c, children;
+
+ if (nvlist_lookup_nvlist_array(nvl, ZPOOL_CONFIG_CHILDREN, &child,
+ &children) == 0) {
+ for (c = 0; c < children; c++)
+ spa_config_clean(child[c]);
+ }
+
+ if (nvlist_lookup_nvlist(nvl, ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0)
+ spa_config_clean(nvroot);
+
+ nvlist_remove(nvl, ZPOOL_CONFIG_VDEV_STATS, DATA_TYPE_UINT64_ARRAY);
+ nvlist_remove(nvl, ZPOOL_CONFIG_SCAN_STATS, DATA_TYPE_UINT64_ARRAY);
+}
+
static int
spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
{
@@ -233,6 +253,7 @@ spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
*/
nvl = NULL;
while ((spa = spa_next(spa)) != NULL) {
+ nvlist_t *nvroot = NULL;
/*
* Skip over our own pool if we're about to remove
* ourselves from the spa namespace or any pool that
@@ -241,7 +262,8 @@ spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
* we don't allow them to be written to the cache file.
*/
if ((spa == target && removing) ||
- !spa_writeable(spa))
+ (spa_state(spa) == POOL_STATE_ACTIVE &&
+ !spa_writeable(spa)))
continue;
mutex_enter(&spa->spa_props_lock);
@@ -260,6 +282,9 @@ spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
VERIFY(nvlist_add_nvlist(nvl, spa->spa_name,
spa->spa_config) == 0);
mutex_exit(&spa->spa_props_lock);
+
+ if (nvlist_lookup_nvlist(nvl, spa->spa_name, &nvroot) == 0)
+ spa_config_clean(nvroot);
}
error = spa_config_write(dp, nvl);
OpenPOWER on IntegriCloud