Skip to content

Commit 6385f4e

Browse files
rincebraintonyhutter
authored andcommitted
Fix unfortunate NULL in spa_update_dspace
After 1325434, we can in certain circumstances end up calling spa_update_dspace with vd->vdev_mg NULL, which ends poorly during vdev removal. So let's not do that further space adjustment when we can't. Reviewed-by: Matthew Ahrens <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rich Ercolani <[email protected]> Closes openzfs#12380 Closes openzfs#12428
1 parent 2f073cc commit 6385f4e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

module/zfs/spa_misc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,14 @@ spa_update_dspace(spa_t *spa)
18541854
spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
18551855
vdev_t *vd =
18561856
vdev_lookup_top(spa, spa->spa_vdev_removal->svr_vdev_id);
1857-
if (vd->vdev_mg->mg_class == spa_normal_class(spa)) {
1857+
/*
1858+
* If the stars align, we can wind up here after
1859+
* vdev_remove_complete() has cleared vd->vdev_mg but before
1860+
* spa->spa_vdev_removal gets cleared, so we must check before
1861+
* we dereference.
1862+
*/
1863+
if (vd->vdev_mg &&
1864+
vd->vdev_mg->mg_class == spa_normal_class(spa)) {
18581865
spa->spa_dspace -= spa_deflate(spa) ?
18591866
vd->vdev_stat.vs_dspace : vd->vdev_stat.vs_space;
18601867
}

0 commit comments

Comments
 (0)