Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
vmware: fix stopped VM volume migration#4758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
80f9b4c54ef6e77cc6b6eee6aacddb2363de172623691ca709973e57235689480fdcbd28ae50979bb82cb5bbe9f5d685a91fdc8255e89cb0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2294,43 +2294,6 @@ private void markVolumesInPool(VMInstanceVO vm, StoragePool destPool, Answer[] h | ||
| } | ||
| } | ||
| private Pair<Long, Long> findClusterAndHostIdForVm(VMInstanceVO vm) { | ||
| Long hostId = vm.getHostId(); | ||
| Long clusterId = null; | ||
| // OfflineVmwareMigration: probably this is null when vm is stopped | ||
| if(hostId == null) { | ||
| hostId = vm.getLastHostId(); | ||
| if (s_logger.isDebugEnabled()) { | ||
| s_logger.debug(String.format("host id is null, using last host id %d", hostId) ); | ||
| } | ||
| } | ||
| if (hostId == null) { | ||
| List<VolumeVO> volumes = _volsDao.findByInstanceAndType(vm.getId(), Type.ROOT); | ||
| if (CollectionUtils.isNotEmpty(volumes)) { | ||
| for (VolumeVO rootVolume : volumes) { | ||
| if (rootVolume.getPoolId() != null) { | ||
| StoragePoolVO pool = _storagePoolDao.findById(rootVolume.getPoolId()); | ||
| if (pool != null && pool.getClusterId() != null) { | ||
| clusterId = pool.getClusterId(); | ||
| List<HostVO> hosts = _hostDao.findHypervisorHostInCluster(pool.getClusterId()); | ||
| if (CollectionUtils.isNotEmpty(hosts)) { | ||
| hostId = hosts.get(0).getId(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (clusterId == null && hostId != null) { | ||
| HostVO host = _hostDao.findById(hostId); | ||
| if (host != null) { | ||
| clusterId = host.getClusterId(); | ||
| } | ||
| } | ||
| return new Pair<>(clusterId, hostId); | ||
| } | ||
| private void migrateThroughHypervisorOrStorage(StoragePool destPool, VMInstanceVO vm) throws StorageUnavailableException, InsufficientCapacityException { | ||
| final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); | ||
| Pair<Long, Long> vmClusterAndHost = findClusterAndHostIdForVm(vm); | ||
nvazquez marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @@ -5913,4 +5876,53 @@ private Pair<JobInfo.Status, String> orchestrateUpdateDefaultNic(final VmWorkUpd | ||
| _jobMgr.marshallResultObject(result)); | ||
| } | ||
| private Pair<Long, Long> findClusterAndHostIdForVmFromVolumes(long vmId) { | ||
| Long clusterId = null; | ||
| Long hostId = null; | ||
| List<VolumeVO> volumes = _volsDao.findByInstance(vmId); | ||
| for (VolumeVO volume : volumes) { | ||
| if (Volume.State.Ready.equals(volume.getState()) && | ||
| volume.getPoolId() != null) { | ||
| StoragePoolVO pool = _storagePoolDao.findById(volume.getPoolId()); | ||
| if (pool != null && pool.getClusterId() != null) { | ||
| clusterId = pool.getClusterId(); | ||
| // hostId to be used only for sending commands, capacity check skipped | ||
| List<HostVO> hosts = _hostDao.findHypervisorHostInCluster(pool.getClusterId()); | ||
| if (CollectionUtils.isNotEmpty(hosts)) { | ||
| hostId = hosts.get(0).getId(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return new Pair<>(clusterId, hostId); | ||
| } | ||
| private Pair<Long, Long> findClusterAndHostIdForVm(VirtualMachine vm) { | ||
| Long hostId = vm.getHostId(); | ||
| Long clusterId = null; | ||
| if(hostId == null) { | ||
| hostId = vm.getLastHostId(); | ||
| if (s_logger.isDebugEnabled()) { | ||
| s_logger.debug(String.format("host id is null, using last host id %d", hostId) ); | ||
| } | ||
| } | ||
| if (hostId == null) { | ||
| return findClusterAndHostIdForVmFromVolumes(vm.getId()); | ||
| } | ||
| HostVO host = _hostDao.findById(hostId); | ||
| if (host != null) { | ||
| clusterId = host.getClusterId(); | ||
| } | ||
| return new Pair<>(clusterId, hostId); | ||
| } | ||
| @Override | ||
| public Pair<Long, Long> findClusterAndHostIdForVm(long vmId) { | ||
| VMInstanceVO vm = _vmDao.findById(vmId); | ||
| if (vm == null) { | ||
| return new Pair<>(null, null); | ||
| } | ||
| return findClusterAndHostIdForVm(vm); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -34,11 +34,6 @@ | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.TimeUnit; | ||
| import com.cloud.hypervisor.vmware.mo.VirtualStorageObjectManagerMO; | ||
| import com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder; | ||
| import com.vmware.vim25.BaseConfigInfoDiskFileBackingInfo; | ||
| import com.vmware.vim25.VStorageObject; | ||
| import com.vmware.vim25.VirtualDiskType; | ||
| import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand; | ||
| import org.apache.cloudstack.storage.command.AttachAnswer; | ||
| import org.apache.cloudstack.storage.command.AttachCommand; | ||
| @@ -84,7 +79,9 @@ | ||
| import com.cloud.hypervisor.vmware.mo.HostStorageSystemMO; | ||
| import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper; | ||
| import com.cloud.hypervisor.vmware.mo.NetworkDetails; | ||
| import com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder; | ||
| import com.cloud.hypervisor.vmware.mo.VirtualMachineMO; | ||
| import com.cloud.hypervisor.vmware.mo.VirtualStorageObjectManagerMO; | ||
| import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost; | ||
| import com.cloud.hypervisor.vmware.resource.VmwareResource; | ||
| import com.cloud.hypervisor.vmware.util.VmwareContext; | ||
| @@ -104,6 +101,7 @@ | ||
| import com.cloud.vm.VmDetailConstants; | ||
| import com.google.common.base.Strings; | ||
| import com.google.gson.Gson; | ||
| import com.vmware.vim25.BaseConfigInfoDiskFileBackingInfo; | ||
| import com.vmware.vim25.DatastoreHostMount; | ||
| import com.vmware.vim25.HostHostBusAdapter; | ||
| import com.vmware.vim25.HostInternetScsiHba; | ||
| @@ -122,11 +120,13 @@ | ||
| import com.vmware.vim25.HostUnresolvedVmfsVolume; | ||
| import com.vmware.vim25.InvalidStateFaultMsg; | ||
| import com.vmware.vim25.ManagedObjectReference; | ||
| import com.vmware.vim25.VStorageObject; | ||
| import com.vmware.vim25.VirtualDeviceBackingInfo; | ||
| import com.vmware.vim25.VirtualDeviceConfigSpec; | ||
| import com.vmware.vim25.VirtualDeviceConfigSpecOperation; | ||
| import com.vmware.vim25.VirtualDisk; | ||
| import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo; | ||
| import com.vmware.vim25.VirtualDiskType; | ||
| import com.vmware.vim25.VirtualMachineConfigSpec; | ||
| import com.vmware.vim25.VmConfigInfo; | ||
| import com.vmware.vim25.VmfsDatastoreExpandSpec; | ||
| @@ -2683,15 +2683,14 @@ public Answer deleteVolume(DeleteCommand cmd) { | ||
| List<VirtualDisk> virtualDisks = vmMo.getVirtualDisks(); | ||
| List<String> managedDatastoreNames = getManagedDatastoreNamesFromVirtualDisks(virtualDisks); | ||
| // Preserve other disks of the VM | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for these changes @shwstppr. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @harikrishna-patnala I've verified the destroy case and have seen any issue. | ||
| List<String> detachedDisks = vmMo.detachAllDisksExcept(vol.getPath(), diskInfo != null ? diskInfo.getDiskDeviceBusName() : null); | ||
| VmwareStorageLayoutHelper.moveVolumeToRootFolder(new DatacenterMO(context, morDc), detachedDisks); | ||
| // let vmMo.destroy to delete volume for us | ||
| // vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class }); | ||
| if (isManaged) { | ||
| List<String> detachedDisks = vmMo.detachAllDisksExcept(vol.getPath(), diskInfo != null ? diskInfo.getDiskDeviceBusName() : null); | ||
| VmwareStorageLayoutHelper.moveVolumeToRootFolder(new DatacenterMO(context, morDc), detachedDisks); | ||
| vmMo.unregisterVm(); | ||
| } | ||
| else { | ||
| } else { | ||
| vmMo.destroy(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.