/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
*/
#include <sys/spa.h>
#include <sys/fs/zfs.h>
#include <sys/vdev_impl.h>
#include <sys/zfs_ioctl.h>
-#include <sys/utsname.h>
#include <sys/systeminfo.h>
#include <sys/sunddi.h>
+#include <sys/zfeature.h>
#ifdef _KERNEL
#include <sys/kobj.h>
#include <sys/zone.h>
* userland pools when doing testing.
*/
char *spa_config_path = ZPOOL_CACHE;
+int zfs_autoimport_disable = 1;
/*
* Called when the module is first loaded, this routine loads the configuration
struct _buf *file;
uint64_t fsize;
+#ifdef _KERNEL
+ if (zfs_autoimport_disable)
+ return;
+#endif
+
/*
* Open the configuration file.
*/
if (kobj_get_filesize(file, &fsize) != 0)
goto out;
- buf = kmem_alloc(fsize, KM_SLEEP | KM_NODEBUG);
+ buf = kmem_alloc(fsize, KM_SLEEP);
/*
* Read the nvlist from the file.
*/
VERIFY(nvlist_size(nvl, &buflen, NV_ENCODE_XDR) == 0);
- buf = kmem_alloc(buflen, KM_SLEEP | KM_NODEBUG);
+ buf = vmem_alloc(buflen, KM_SLEEP);
temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
VERIFY(nvlist_pack(nvl, &buf, &buflen, NV_ENCODE_XDR,
(void) vn_remove(temp, UIO_SYSSPACE, RMFILE);
- kmem_free(buf, buflen);
+ vmem_free(buf, buflen);
kmem_free(temp, MAXPATHLEN);
}
/*
* Synchronize pool configuration to disk. This must be called with the
- * namespace lock held.
+ * namespace lock held. Synchronizing the pool cache is typically done after
+ * the configuration has been synced to the MOS. This exposes a window where
+ * the MOS config will have been updated but the cache file has not. If
+ * the system were to crash at that instant then the cached config may not
+ * contain the correct information to open the pool and an explicity import
+ * would be required.
*/
void
spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
{
spa_config_dirent_t *dp, *tdp;
nvlist_t *nvl;
+ char *pool_name;
ASSERT(MUTEX_HELD(&spa_namespace_lock));
*/
nvl = NULL;
while ((spa = spa_next(spa)) != NULL) {
- if (spa == target && removing)
+ /*
+ * Skip over our own pool if we're about to remove
+ * ourselves from the spa namespace or any pool that
+ * is readonly. Since we cannot guarantee that a
+ * readonly pool would successfully import upon reboot,
+ * we don't allow them to be written to the cache file.
+ */
+ if ((spa == target && removing) ||
+ !spa_writeable(spa))
continue;
mutex_enter(&spa->spa_props_lock);
VERIFY(nvlist_alloc(&nvl, NV_UNIQUE_NAME,
KM_SLEEP) == 0);
- VERIFY(nvlist_add_nvlist(nvl, spa->spa_name,
+ if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
+ VERIFY0(nvlist_lookup_string(spa->spa_config,
+ ZPOOL_CONFIG_POOL_NAME, &pool_name));
+ } else
+ pool_name = spa_name(spa);
+
+ VERIFY(nvlist_add_nvlist(nvl, pool_name,
spa->spa_config) == 0);
mutex_exit(&spa->spa_props_lock);
}
/*
* Generate the pool's configuration based on the current in-core state.
+ *
* We infer whether to generate a complete config or just one top-level config
* based on whether vd is the root vdev.
*/
unsigned long hostid = 0;
boolean_t locked = B_FALSE;
uint64_t split_guid;
+ char *pool_name;
if (vd == NULL) {
vd = rvd;
if (txg == -1ULL)
txg = spa->spa_config_txg;
+ /*
+ * Originally, users had to handle spa namespace collisions by either
+ * exporting the already imported pool or by specifying a new name for
+ * the pool with a conflicting name. In the case of root pools from
+ * virtual guests, neither approach to collision resolution is
+ * reasonable. This is addressed by extending the new name syntax with
+ * an option to specify that the new name is temporary. When specified,
+ * ZFS_IMPORT_TEMP_NAME will be set in spa->spa_import_flags to tell us
+ * to use the previous name, which we do below.
+ */
+ if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
+ VERIFY0(nvlist_lookup_string(spa->spa_config,
+ ZPOOL_CONFIG_POOL_NAME, &pool_name));
+ } else
+ pool_name = spa_name(spa);
+
VERIFY(nvlist_alloc(&config, NV_UNIQUE_NAME, KM_SLEEP) == 0);
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_VERSION,
spa_version(spa)) == 0);
VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME,
- spa_name(spa)) == 0);
+ pool_name) == 0);
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE,
spa_state(spa)) == 0);
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG,
txg) == 0);
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID,
spa_guid(spa)) == 0);
+ VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_ERRATA,
+ spa->spa_errata) == 0);
+ VERIFY(spa->spa_comment == NULL || nvlist_add_string(config,
+ ZPOOL_CONFIG_COMMENT, spa->spa_comment) == 0);
+
+
#ifdef _KERNEL
hostid = zone_get_hostid(NULL);
#else /* _KERNEL */
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_HOSTID,
hostid) == 0);
}
- VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME,
- utsname.nodename) == 0);
+ VERIFY0(nvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME,
+ utsname()->nodename));
if (vd != rvd) {
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_TOP_GUID,
VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, nvroot) == 0);
nvlist_free(nvroot);
+ /*
+ * Store what's necessary for reading the MOS in the label.
+ */
+ VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_FEATURES_FOR_READ,
+ spa->spa_label_features) == 0);
+
if (getstats && spa_load_state(spa) == SPA_LOAD_NONE) {
ddt_histogram_t *ddh;
ddt_stat_t *dds;
module_param(spa_config_path, charp, 0444);
MODULE_PARM_DESC(spa_config_path, "SPA config file (/etc/zfs/zpool.cache)");
+
+module_param(zfs_autoimport_disable, int, 0644);
+MODULE_PARM_DESC(zfs_autoimport_disable, "Disable pool import at module load");
+
#endif