diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java index 529e26125f3..059e6e4139a 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java @@ -34,7 +34,6 @@ import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.GuestOSVO; -import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.VolumeDao; @@ -103,30 +102,30 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru List volumes = _volumeDao.findByInstance(vm.getId()); + // it's OK in this case to send a detach command to the host for a root volume as this + // will simply lead to the SR that supports the root volume being removed if (volumes != null) { for (VolumeVO volume : volumes) { - if (volume.getVolumeType() == Volume.Type.DATADISK) { - StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId()); + StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId()); - // storagePool should be null if we are expunging a volume that was never - // attached to a VM that was started (the "trick" for storagePool to be null - // is that none of the VMs this volume may have been attached to were ever started, - // so the volume was never assigned to a storage pool) - if (storagePool != null && storagePool.isManaged()) { - DataTO volTO = _volFactory.getVolume(volume.getId()).getTO(); - DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType()); + // storagePool should be null if we are expunging a volume that was never + // attached to a VM that was started (the "trick" for storagePool to be null + // is that none of the VMs this volume may have been attached to were ever started, + // so the volume was never assigned to a storage pool) + if (storagePool != null && storagePool.isManaged()) { + DataTO volTO = _volFactory.getVolume(volume.getId()).getTO(); + DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType()); - DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName()); + DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName()); - cmd.setManaged(true); + cmd.setManaged(true); - cmd.setStorageHost(storagePool.getHostAddress()); - cmd.setStoragePort(storagePool.getPort()); + cmd.setStorageHost(storagePool.getHostAddress()); + cmd.setStoragePort(storagePool.getPort()); - cmd.set_iScsiName(volume.get_iScsiName()); + cmd.set_iScsiName(volume.get_iScsiName()); - commands.add(cmd); - } + commands.add(cmd); } } }