Skip to content

Commit

Permalink
Make volume deletion more robust in case the volume was already delet…
Browse files Browse the repository at this point in the history
  • Loading branch information
moio authored and MalloZup committed Dec 12, 2019
1 parent dff86eb commit 4d5aa53
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libvirt/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,21 @@ func volumeDelete(client *Client, key string) error {
// Does not solve the problem but it makes it happen less often.
_, err = volume.GetXMLDesc(0)
if err != nil {
return fmt.Errorf("Can't retrieve volume %s XML desc: %s", key, err)
virErr := err.(libvirt.Error)
if virErr.Code != libvirt.ERR_NO_STORAGE_VOL {
return fmt.Errorf("Can't retrieve volume %s XML desc: %s", key, err)
}
// Volume is probably gone already, getting its XML description is pointless
}

err = volume.Delete(0)
if err != nil {
return fmt.Errorf("Can't delete volume %s: %s", key, err)
virErr := err.(libvirt.Error)
if virErr.Code != libvirt.ERR_NO_STORAGE_VOL {
return fmt.Errorf("Can't delete volume %s: %s", key, err)
}
// Volume is gone already
return nil
}

return volumeWaitDeleted(client.libvirt, key)
Expand Down

0 comments on commit 4d5aa53

Please sign in to comment.