Skip to content

Commit

Permalink
Fix unfortunate NULL in spa_update_dspace
Browse files Browse the repository at this point in the history
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 <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes openzfs#12380
Closes openzfs#12428
  • Loading branch information
rincebrain authored and behlendorf committed Aug 24, 2021
1 parent eb17f92 commit f7b2b2d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion module/zfs/spa_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,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;
}
Expand Down

0 comments on commit f7b2b2d

Please sign in to comment.