Skip to content

Commit f1ca799

Browse files
authored
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 #12380 Closes #12428
1 parent 1b06b03 commit f1ca799

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
@@ -1853,7 +1853,14 @@ spa_update_dspace(spa_t *spa)
18531853
spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
18541854
vdev_t *vd =
18551855
vdev_lookup_top(spa, spa->spa_vdev_removal->svr_vdev_id);
1856-
if (vd->vdev_mg->mg_class == spa_normal_class(spa)) {
1856+
/*
1857+
* If the stars align, we can wind up here after
1858+
* vdev_remove_complete() has cleared vd->vdev_mg but before
1859+
* spa->spa_vdev_removal gets cleared, so we must check before
1860+
* we dereference.
1861+
*/
1862+
if (vd->vdev_mg &&
1863+
vd->vdev_mg->mg_class == spa_normal_class(spa)) {
18571864
spa->spa_dspace -= spa_deflate(spa) ?
18581865
vd->vdev_stat.vs_dspace : vd->vdev_stat.vs_space;
18591866
}

0 commit comments

Comments
 (0)