Skip to content

Commit

Permalink
Hold SCL_VDEV when counting leaves
Browse files Browse the repository at this point in the history
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 openzfs#7286
  • Loading branch information
ofaaland authored and behlendorf committed Mar 9, 2018
1 parent ebed90a commit 743253d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 743253d

Please sign in to comment.