Illumos #3639 zpool.cache should skip over readonly pools
[zfs.git] / module / zfs / spa_config.c
index c868841..5e5b405 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2011 by Delphix. All rights reserved.
+ * Copyright (c) 2012 by Delphix. All rights reserved.
  */
 
 #include <sys/spa.h>
@@ -35,6 +35,7 @@
 #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>
@@ -64,6 +65,7 @@ static uint64_t spa_config_generation = 1;
  * userland pools when doing testing.
  */
 char *spa_config_path = ZPOOL_CACHE;
+int zfs_autoimport_disable = 0;
 
 /*
  * Called when the module is first loaded, this routine loads the configuration
@@ -80,6 +82,9 @@ spa_config_load(void)
        struct _buf *file;
        uint64_t fsize;
 
+       if (zfs_autoimport_disable)
+               return;
+
        /*
         * Open the configuration file.
         */
@@ -220,7 +225,15 @@ spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
                 */
                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);
@@ -408,6 +421,12 @@ spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
        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;
@@ -501,4 +520,8 @@ EXPORT_SYMBOL(spa_config_update);
 
 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