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 <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Rich Ercolani <[email protected]>
Closes openzfs#12380 
Closes openzfs#12428
  • Loading branch information
rincebrain authored and behlendorf committed Aug 23, 2021
1 parent 2a15707 commit 6ec713c
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 @@ -1868,7 +1868,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 6ec713c

Please sign in to comment.