]> git.proxmox.com Git - mirror_zfs.git/commitdiff
module param callbacks check for initialized spa
authorOlaf Faaland <faaland1@llnl.gov>
Fri, 11 May 2018 19:46:07 +0000 (12:46 -0700)
committerTony Hutter <hutter2@llnl.gov>
Fri, 6 Jul 2018 09:46:51 +0000 (02:46 -0700)
Callbacks provided for module parameters are executed both
after the module is loaded, when a user alters it via sysfs, e.g
echo bar > /sys/modules/zfs/parameters/foo

as well as when the module is loaded with an argument, e.g.
modprobe zfs foo=bar

In the latter case, the init functions likely have not run yet,
including spa_init() which initializes the namespace lock so it is safe
to use.

Instead of immediately taking the namespace lock and attemping to
iterate over initialized spa structures, check whether spa_mode_global
is nonzero.  This is set by spa_init() after it has initialized the
namespace lock.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #7496
Closes #7521

module/zfs/mmp.c
module/zfs/vdev_disk.c

index 3b74a6b6186b5ac9eeb5868c40af37912e943923..7523310cd7bd319c8bd9beff8044f515da6e5547 100644 (file)
@@ -607,7 +607,8 @@ param_set_multihost_interval(const char *val, zfs_kernel_param_t *kp)
        if (ret < 0)
                return (ret);
 
-       mmp_signal_all_threads();
+       if (spa_mode_global != 0)
+               mmp_signal_all_threads();
 
        return (ret);
 }
index d62128353c9e20b79b7281486c7b482add42531a..6761e755a7e34b388c962ec2602138a1ee78cb1d 100644 (file)
@@ -815,19 +815,21 @@ param_set_vdev_scheduler(const char *val, zfs_kernel_param_t *kp)
        if ((p = strchr(val, '\n')) != NULL)
                *p = '\0';
 
-       mutex_enter(&spa_namespace_lock);
-       while ((spa = spa_next(spa)) != NULL) {
-               if (spa_state(spa) != POOL_STATE_ACTIVE ||
-                   !spa_writeable(spa) || spa_suspended(spa))
-                       continue;
-
-               spa_open_ref(spa, FTAG);
-               mutex_exit(&spa_namespace_lock);
-               vdev_elevator_switch(spa->spa_root_vdev, (char *)val);
+       if (spa_mode_global != 0) {
                mutex_enter(&spa_namespace_lock);
-               spa_close(spa, FTAG);
+               while ((spa = spa_next(spa)) != NULL) {
+                       if (spa_state(spa) != POOL_STATE_ACTIVE ||
+                           !spa_writeable(spa) || spa_suspended(spa))
+                               continue;
+
+                       spa_open_ref(spa, FTAG);
+                       mutex_exit(&spa_namespace_lock);
+                       vdev_elevator_switch(spa->spa_root_vdev, (char *)val);
+                       mutex_enter(&spa_namespace_lock);
+                       spa_close(spa, FTAG);
+               }
+               mutex_exit(&spa_namespace_lock);
        }
-       mutex_exit(&spa_namespace_lock);
 
        return (param_set_charp(val, kp));
 }