]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/spa_config.c
Fix typo/etc in module/zfs/zfs_ctldir.c
[mirror_zfs.git] / module / zfs / spa_config.c
index 2715898cc09e7aac2659e3ce65bfd4fa4fd666f8..8616abda37bdfd34f2e6cd6f090d123efc3ec0a3 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, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
  * Copyright 2017 Joyent, Inc.
  */
 
@@ -55,7 +55,7 @@
  * configuration information.  When the module loads, we read this information
  * from /etc/zfs/zpool.cache and populate the SPA namespace.  This namespace is
  * maintained independently in spa.c.  Whenever the namespace is modified, or
- * the configuration of a pool is changed, we call spa_config_sync(), which
+ * the configuration of a pool is changed, we call spa_write_cachefile(), which
  * walks through all the active pools and writes the configuration to disk.
  */
 
@@ -147,6 +147,26 @@ out:
        kobj_close_file(file);
 }
 
+static int
+spa_config_remove(spa_config_dirent_t *dp)
+{
+#if defined(__linux__) && defined(_KERNEL)
+       int error, flags = FWRITE | FTRUNC;
+       uio_seg_t seg = UIO_SYSSPACE;
+       vnode_t *vp;
+
+       error = vn_open(dp->scd_path, seg, flags, 0644, &vp, 0, 0);
+       if (error == 0) {
+               (void) VOP_FSYNC(vp, FSYNC, kcred, NULL);
+               (void) VOP_CLOSE(vp, 0, 1, 0, kcred, NULL);
+       }
+
+       return (error);
+#else
+       return (vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE));
+#endif
+}
+
 static int
 spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
 {
@@ -161,7 +181,10 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
         * If the nvlist is empty (NULL), then remove the old cachefile.
         */
        if (nvl == NULL) {
-               err = vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
+               err = spa_config_remove(dp);
+               if (err == ENOENT)
+                       err = 0;
+
                return (err);
        }
 
@@ -174,9 +197,9 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
 #if defined(__linux__) && defined(_KERNEL)
        /*
         * Write the configuration to disk.  Due to the complexity involved
-        * in performing a rename from within the kernel the file is truncated
-        * and overwritten in place.  In the event of an error the file is
-        * unlinked to make sure we always have a consistent view of the data.
+        * in performing a rename and remove from within the kernel the file
+        * is instead truncated and overwritten in place.  This way we always
+        * have a consistent view of the data or a zero length file.
         */
        err = vn_open(dp->scd_path, UIO_SYSSPACE, oflags, 0644, &vp, 0, 0);
        if (err == 0) {
@@ -186,9 +209,8 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
                        err = VOP_FSYNC(vp, FSYNC, kcred, NULL);
 
                (void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);
-
                if (err)
-                       (void) vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
+                       (void) spa_config_remove(dp);
        }
 #else
        /*
@@ -227,7 +249,7 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
  * would be required.
  */
 void
-spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
+spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent)
 {
        spa_config_dirent_t *dp, *tdp;
        nvlist_t *nvl;
@@ -305,7 +327,7 @@ spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent)
                 */
                if (target->spa_ccw_fail_time == 0) {
                        zfs_ereport_post(FM_EREPORT_ZFS_CONFIG_CACHE_WRITE,
-                           target, NULL, NULL, 0, 0);
+                           target, NULL, NULL, NULL, 0, 0);
                }
                target->spa_ccw_fail_time = gethrtime();
                spa_async_request(target, SPA_ASYNC_CONFIG_UPDATE);
@@ -371,7 +393,8 @@ void
 spa_config_set(spa_t *spa, nvlist_t *config)
 {
        mutex_enter(&spa->spa_props_lock);
-       nvlist_free(spa->spa_config);
+       if (spa->spa_config != NULL && spa->spa_config != config)
+               nvlist_free(spa->spa_config);
        spa->spa_config = config;
        mutex_exit(&spa->spa_props_lock);
 }
@@ -391,7 +414,6 @@ spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
        boolean_t locked = B_FALSE;
        uint64_t split_guid;
        char *pool_name;
-       int config_gen_flags = 0;
 
        if (vd == NULL) {
                vd = rvd;
@@ -436,19 +458,12 @@ spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
                fnvlist_add_string(config, ZPOOL_CONFIG_COMMENT,
                    spa->spa_comment);
 
-#ifdef _KERNEL
-       hostid = 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, &hostid);
-#endif /* _KERNEL */
+       hostid = spa_get_hostid();
        if (hostid != 0)
                fnvlist_add_uint64(config, ZPOOL_CONFIG_HOSTID, hostid);
        fnvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME, utsname()->nodename);
 
+       int config_gen_flags = 0;
        if (vd != rvd) {
                fnvlist_add_uint64(config, ZPOOL_CONFIG_TOP_GUID,
                    vd->vdev_top->vdev_guid);
@@ -561,6 +576,18 @@ spa_config_update(spa_t *spa, int what)
                 */
                for (c = 0; c < rvd->vdev_children; c++) {
                        vdev_t *tvd = rvd->vdev_child[c];
+
+                       /*
+                        * Explicitly skip vdevs that are indirect or
+                        * log vdevs that are being removed. The reason
+                        * is that both of those can have vdev_ms_array
+                        * set to 0 and we wouldn't want to change their
+                        * metaslab size nor call vdev_expand() on them.
+                        */
+                       if (!vdev_is_concrete(tvd) ||
+                           (tvd->vdev_islog && tvd->vdev_removing))
+                               continue;
+
                        if (tvd->vdev_ms_array == 0)
                                vdev_metaslab_set_size(tvd);
                        vdev_expand(tvd, txg);
@@ -576,15 +603,16 @@ spa_config_update(spa_t *spa, int what)
        /*
         * Update the global config cache to reflect the new mosconfig.
         */
-       if (!spa->spa_is_root)
-               spa_config_sync(spa, B_FALSE, what != SPA_CONFIG_UPDATE_POOL);
+       if (!spa->spa_is_root) {
+               spa_write_cachefile(spa, B_FALSE,
+                   what != SPA_CONFIG_UPDATE_POOL);
+       }
 
        if (what == SPA_CONFIG_UPDATE_POOL)
                spa_config_update(spa, SPA_CONFIG_UPDATE_VDEVS);
 }
 
-#if defined(_KERNEL) && defined(HAVE_SPL)
-EXPORT_SYMBOL(spa_config_sync);
+#if defined(_KERNEL)
 EXPORT_SYMBOL(spa_config_load);
 EXPORT_SYMBOL(spa_all_configs);
 EXPORT_SYMBOL(spa_config_set);