]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Hold SCL_VDEV when counting leaves
authorOlaf Faaland <faaland1@llnl.gov>
Thu, 8 Mar 2018 23:39:07 +0000 (15:39 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 9 Mar 2018 23:42:54 +0000 (15:42 -0800)
A config lock should be held while vdev_count_leaves() walks the tree,
otherwise the pointers reference may become invalid during the walk.

SCL_VDEV is a minimal lock provided for such uses cases.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #7286

module/zfs/vdev.c

index c73b2e7f2ddd3081a4cd94b07a2930ca776f2908..172485f6e495e5186de2d8d3f4a18c3d8880f56a 100644 (file)
@@ -209,7 +209,13 @@ vdev_count_leaves_impl(vdev_t *vd)
 int
 vdev_count_leaves(spa_t *spa)
 {
-       return (vdev_count_leaves_impl(spa->spa_root_vdev));
+       int rc;
+
+       spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
+       rc = vdev_count_leaves_impl(spa->spa_root_vdev);
+       spa_config_exit(spa, SCL_VDEV, FTAG);
+
+       return (rc);
 }
 
 void