diff --git a/module/zfs/spa_misc.c b/module/zfs/spa_misc.c index add108b779..00515db027 100644 --- a/module/zfs/spa_misc.c +++ b/module/zfs/spa_misc.c @@ -1854,7 +1854,14 @@ spa_update_dspace(spa_t *spa) spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); vdev_t *vd = vdev_lookup_top(spa, spa->spa_vdev_removal->svr_vdev_id); - if (vd->vdev_mg->mg_class == spa_normal_class(spa)) { + /* + * If the stars align, we can wind up here after + * vdev_remove_complete() has cleared vd->vdev_mg but before + * spa->spa_vdev_removal gets cleared, so we must check before + * we dereference. + */ + if (vd->vdev_mg && + vd->vdev_mg->mg_class == spa_normal_class(spa)) { spa->spa_dspace -= spa_deflate(spa) ? vd->vdev_stat.vs_dspace : vd->vdev_stat.vs_space; }