Skip to content

Commit 90316b2

Browse files
VMware 80u2 and 80u3 updates/fixes (#10586)
* VMware - Ignore disk not found error on cleanup when the VM disk doesn't exists * VMware - Retry powerOn on lock issues * addressed comments * Update CPVM reboot tests - wait for the agent to Disconnect and back Up * Retry moveDatastoreFile when any file access issue while creating volume from snapshot * Update full clone flag when restoring vm using root disk offering with more size than the template size * refactored (mainly,for diskInfo - causing NPE in some cases) * Retry moveDatastoreFile when there is any file access issue
1 parent 8f8c685 commit 90316b2

File tree

6 files changed

+157
-82
lines changed

6 files changed

+157
-82
lines changed

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,6 @@ protected StartAnswer execute(StartCommand cmd) {
20422042
VirtualMachineDefinedProfileSpec diskProfileSpec = null;
20432043
VirtualMachineDefinedProfileSpec vmProfileSpec = null;
20442044

2045-
20462045
DeployAsIsInfoTO deployAsIsInfo = vmSpec.getDeployAsIsInfo();
20472046
boolean deployAsIs = deployAsIsInfo != null;
20482047

@@ -2086,7 +2085,6 @@ protected StartAnswer execute(StartCommand cmd) {
20862085
}
20872086

20882087
VirtualMachineDiskInfoBuilder diskInfoBuilder = null;
2089-
VirtualDevice[] nicDevices = null;
20902088
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
20912089
DiskControllerType systemVmScsiControllerType = DiskControllerType.lsilogic;
20922090
int firstScsiControllerBusNum = 0;
@@ -2103,7 +2101,6 @@ protected StartAnswer execute(StartCommand cmd) {
21032101
diskDatastores = vmMo.getAllDiskDatastores();
21042102
diskInfoBuilder = vmMo.getDiskInfoBuilder();
21052103
hasSnapshot = vmMo.hasSnapshot();
2106-
nicDevices = vmMo.getNicDevices();
21072104

21082105
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
21092106
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
@@ -2119,17 +2116,20 @@ protected StartAnswer execute(StartCommand cmd) {
21192116
}
21202117

21212118
takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
2119+
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
21222120

2123-
if (getVmPowerState(vmMo) != PowerState.PowerOff)
2124-
vmMo.safePowerOff(_shutdownWaitMs);
2121+
if (vmMo != null) {
2122+
if (getVmPowerState(vmMo) != PowerState.PowerOff)
2123+
vmMo.safePowerOff(_shutdownWaitMs);
21252124

2126-
diskInfoBuilder = vmMo.getDiskInfoBuilder();
2127-
hasSnapshot = vmMo.hasSnapshot();
2128-
diskDatastores = vmMo.getAllDiskDatastores();
2125+
diskInfoBuilder = vmMo.getDiskInfoBuilder();
2126+
hasSnapshot = vmMo.hasSnapshot();
2127+
diskDatastores = vmMo.getAllDiskDatastores();
21292128

2130-
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
2131-
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
2132-
numScsiControllerForSystemVm, firstScsiControllerBusNum, deployAsIs);
2129+
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
2130+
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
2131+
numScsiControllerForSystemVm, firstScsiControllerBusNum, deployAsIs);
2132+
}
21332133
} else {
21342134
// If a VM with the same name is found in a different cluster in the DC, unregister the old VM and configure a new VM (cold-migration).
21352135
VirtualMachineMO existingVmInDc = dcMo.findVm(vmInternalCSName);
@@ -2146,7 +2146,7 @@ protected StartAnswer execute(StartCommand cmd) {
21462146
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
21472147
if (vmMo == null) {
21482148
logger.info("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it");
2149-
vmMo = takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
2149+
takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
21502150
}
21512151
} else {
21522152
DiskTO rootDisk = null;
@@ -2256,11 +2256,11 @@ protected StartAnswer execute(StartCommand cmd) {
22562256
vmConfigSpec.setCpuHotAddEnabled(vmMo.isCpuHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm());
22572257
}
22582258

2259-
if(!vmMo.isMemoryHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()){
2259+
if (!vmMo.isMemoryHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()) {
22602260
logger.warn("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName);
22612261
}
22622262

2263-
if(!vmMo.isCpuHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()){
2263+
if (!vmMo.isCpuHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()) {
22642264
logger.warn("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName);
22652265
}
22662266

@@ -2593,7 +2593,7 @@ protected StartAnswer execute(StartCommand cmd) {
25932593

25942594
Map<String, Map<String, String>> iqnToData = new HashMap<>();
25952595

2596-
postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, ideControllerKey, scsiControllerKey, iqnToData, hyperHost, context);
2596+
postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, iqnToData, hyperHost, context);
25972597

25982598
//
25992599
// Power-on VM
@@ -2731,14 +2731,24 @@ private void syncVolumeDatastoreAndPathForDatastoreCluster(DiskTO vol, VirtualMa
27312731
}
27322732

27332733
private boolean powerOnVM(final VirtualMachineMO vmMo, final String vmInternalCSName, final String vmNameOnVcenter) throws Exception {
2734-
int retry = 20;
2735-
while (retry-- > 0) {
2734+
final int retry = 20;
2735+
int retryAttempt = 0;
2736+
while (++retryAttempt <= retry) {
27362737
try {
2738+
logger.debug(String.format("VM %s, powerOn attempt #%d", vmInternalCSName, retryAttempt));
27372739
return vmMo.powerOn();
27382740
} catch (Exception e) {
27392741
logger.info(String.format("Got exception while power on VM %s with hostname %s", vmInternalCSName, vmNameOnVcenter), e);
2740-
if (e.getMessage() != null && e.getMessage().contains("File system specific implementation of Ioctl[file] failed")) {
2742+
if (e.getMessage() != null &&
2743+
(e.getMessage().contains("File system specific implementation of Ioctl[file] failed") ||
2744+
e.getMessage().contains("Unable to access file") ||
2745+
e.getMessage().contains("it is locked"))) {
27412746
logger.debug(String.format("Failed to power on VM %s with hostname %s. Retrying", vmInternalCSName, vmNameOnVcenter));
2747+
try {
2748+
Thread.sleep(1000);
2749+
} catch (InterruptedException ie) {
2750+
logger.debug(String.format("Waiting to power on VM %s been interrupted: ", vmInternalCSName));
2751+
}
27422752
} else {
27432753
throw e;
27442754
}
@@ -3292,7 +3302,7 @@ private void tearDownVm(VirtualMachineMO vmMo) throws Exception {
32923302

32933303
int getReservedMemoryMb(VirtualMachineTO vmSpec) {
32943304
if (vmSpec.getDetails().get(VMwareGuru.VmwareReserveMemory.key()).equalsIgnoreCase("true")) {
3295-
if(vmSpec.getDetails().get(VmDetailConstants.RAM_RESERVATION) != null){
3305+
if (vmSpec.getDetails().get(VmDetailConstants.RAM_RESERVATION) != null) {
32963306
float reservedMemory = (vmSpec.getMaxRam() * Float.parseFloat(vmSpec.getDetails().get(VmDetailConstants.RAM_RESERVATION)));
32973307
return (int) (reservedMemory / ResourceType.bytesToMiB);
32983308
}
@@ -3630,18 +3640,18 @@ private Pair<String, String> getVMDiskInfo(String volumePath, boolean isManaged,
36303640

36313641
private VirtualMachineDiskInfo getMatchingExistingDisk(VirtualMachineDiskInfoBuilder diskInfoBuilder, DiskTO vol, VmwareHypervisorHost hyperHost, VmwareContext context)
36323642
throws Exception {
3633-
if (diskInfoBuilder != null) {
3634-
VolumeObjectTO volume = (VolumeObjectTO) vol.getData();
3635-
String chainInfo = volume.getChainInfo();
3636-
Map<String, String> details = vol.getDetails();
3637-
boolean isManaged = details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED));
3638-
String iScsiName = details.get(DiskTO.IQN);
3639-
String datastoreUUID = volume.getDataStore().getUuid();
3640-
3641-
return getMatchingExistingDiskWithVolumeDetails(diskInfoBuilder, volume.getPath(), chainInfo, isManaged, iScsiName, datastoreUUID, hyperHost, context);
3642-
} else {
3643+
if (diskInfoBuilder == null) {
36433644
return null;
36443645
}
3646+
3647+
VolumeObjectTO volume = (VolumeObjectTO) vol.getData();
3648+
String chainInfo = volume.getChainInfo();
3649+
Map<String, String> details = vol.getDetails();
3650+
boolean isManaged = details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED));
3651+
String iScsiName = details.get(DiskTO.IQN);
3652+
String datastoreUUID = volume.getDataStore().getUuid();
3653+
3654+
return getMatchingExistingDiskWithVolumeDetails(diskInfoBuilder, volume.getPath(), chainInfo, isManaged, iScsiName, datastoreUUID, hyperHost, context);
36453655
}
36463656

36473657
private String getDiskController(VirtualMachineMO vmMo, VirtualMachineDiskInfo matchingExistingDisk, DiskTO vol, Pair<String, String> controllerInfo, boolean deployAsIs) throws Exception {
@@ -3666,34 +3676,36 @@ private String getDiskController(VirtualMachineMO vmMo, VirtualMachineDiskInfo m
36663676
return VmwareHelper.getControllerBasedOnDiskType(controllerInfo, vol);
36673677
}
36683678

3669-
private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO[] sortedDisks, int ideControllerKey,
3670-
int scsiControllerKey, Map<String, Map<String, String>> iqnToData, VmwareHypervisorHost hyperHost, VmwareContext context) throws Exception {
3679+
private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO[] sortedDisks,
3680+
Map<String, Map<String, String>> iqnToData, VmwareHypervisorHost hyperHost, VmwareContext context) throws Exception {
36713681
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
36723682

36733683
for (DiskTO vol : sortedDisks) {
36743684
if (vol.getType() == Volume.Type.ISO)
36753685
continue;
36763686

3677-
VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
3678-
36793687
VirtualMachineDiskInfo diskInfo = getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
3680-
assert (diskInfo != null);
3688+
if (diskInfo == null) {
3689+
continue;
3690+
}
36813691

36823692
String[] diskChain = diskInfo.getDiskChain();
3683-
assert (diskChain.length > 0);
3693+
if (diskChain.length <= 0) {
3694+
continue;
3695+
}
36843696

3685-
Map<String, String> details = vol.getDetails();
3686-
boolean managed = false;
3697+
DatastoreFile file = new DatastoreFile(diskChain[0]);
36873698

3699+
boolean managed = false;
3700+
Map<String, String> details = vol.getDetails();
36883701
if (details != null) {
36893702
managed = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
36903703
}
36913704

3692-
DatastoreFile file = new DatastoreFile(diskChain[0]);
3705+
VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
36933706

36943707
if (managed) {
36953708
DatastoreFile originalFile = new DatastoreFile(volumeTO.getPath());
3696-
36973709
if (!file.getFileBaseName().equalsIgnoreCase(originalFile.getFileBaseName())) {
36983710
if (logger.isInfoEnabled())
36993711
logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + diskChain[0]);
@@ -3706,7 +3718,6 @@ private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO v
37063718
}
37073719

37083720
VolumeObjectTO volInSpec = getVolumeInSpec(vmSpec, volumeTO);
3709-
37103721
if (volInSpec != null) {
37113722
if (managed) {
37123723
Map<String, String> data = new HashMap<>();
@@ -3871,20 +3882,20 @@ private DatastoreMO getDataStoreWhereDiskExists(VmwareHypervisorHost hyperHost,
38713882
if (diskInfo != null) {
38723883
logger.info("Found existing disk info from volume path: " + volume.getPath());
38733884
return dsMo;
3874-
} else {
3875-
String chainInfo = volume.getChainInfo();
3876-
if (chainInfo != null) {
3877-
VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
3878-
if (infoInChain != null) {
3879-
String[] disks = infoInChain.getDiskChain();
3880-
if (disks.length > 0) {
3881-
for (String diskPath : disks) {
3882-
DatastoreFile file = new DatastoreFile(diskPath);
3883-
diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName);
3884-
if (diskInfo != null) {
3885-
logger.info("Found existing disk from chain info: " + diskPath);
3886-
return dsMo;
3887-
}
3885+
}
3886+
3887+
String chainInfo = volume.getChainInfo();
3888+
if (chainInfo != null) {
3889+
VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
3890+
if (infoInChain != null) {
3891+
String[] disks = infoInChain.getDiskChain();
3892+
if (disks.length > 0) {
3893+
for (String diskPath : disks) {
3894+
DatastoreFile file = new DatastoreFile(diskPath);
3895+
diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName);
3896+
if (diskInfo != null) {
3897+
logger.info("Found existing disk from chain info: " + diskPath);
3898+
return dsMo;
38883899
}
38893900
}
38903901
}
@@ -4747,7 +4758,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
47474758
Map<Integer, Long> volumeDeviceKey = new HashMap<>();
47484759
if (cmd instanceof MigrateVolumeCommand) { // Else device keys will be found in relocateVirtualMachine
47494760
MigrateVolumeCommand mcmd = (MigrateVolumeCommand) cmd;
4750-
addVolumeDiskmapping(vmMo, volumeDeviceKey, mcmd.getVolumePath(), mcmd.getVolumeId());
4761+
addVolumeDiskMapping(vmMo, volumeDeviceKey, mcmd.getVolumePath(), mcmd.getVolumeId());
47514762
if (logger.isTraceEnabled()) {
47524763
for (Integer diskId: volumeDeviceKey.keySet()) {
47534764
logger.trace(String.format("Disk to migrate has disk id %d and volumeId %d", diskId, volumeDeviceKey.get(diskId)));
@@ -4765,9 +4776,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
47654776

47664777
Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObjectToList, Command cmd, Map<Integer, Long> volumeDeviceKey) throws Exception {
47674778
List<VolumeObjectTO> volumeToList;
4768-
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
47694779
VirtualDisk[] disks = vmMo.getAllDiskDevice();
4770-
Answer answer;
47714780
if (logger.isTraceEnabled()) {
47724781
logger.trace(String.format("creating answer for %s", cmd.getClass().getSimpleName()));
47734782
}
@@ -4784,7 +4793,7 @@ Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObje
47844793
return new Answer(cmd, false, null);
47854794
}
47864795

4787-
private void addVolumeDiskmapping(VirtualMachineMO vmMo, Map<Integer, Long> volumeDeviceKey, String volumePath, long volumeId) throws Exception {
4796+
private void addVolumeDiskMapping(VirtualMachineMO vmMo, Map<Integer, Long> volumeDeviceKey, String volumePath, long volumeId) throws Exception {
47884797
if (logger.isDebugEnabled()) {
47894798
logger.debug(String.format("locating disk for volume (%d) using path %s", volumeId, volumePath));
47904799
}
@@ -4919,7 +4928,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
49194928
VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster;
49204929
String targetDsName = cmd.getTargetPool().getUuid();
49214930
morDestinationDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(dsHost, targetDsName);
4922-
if(morDestinationDS == null) {
4931+
if (morDestinationDS == null) {
49234932
String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost.getHyperHostName();
49244933
logger.error(msg);
49254934
throw new CloudRuntimeException(msg);
@@ -5886,6 +5895,11 @@ protected Answer execute(CleanupVMCommand cmd) {
58865895
logger.debug(msg);
58875896
return new Answer(cmd, true, msg);
58885897
} catch (Exception e) {
5898+
if (e.getMessage().contains("was not found")) {
5899+
String msg = String.format("%s - VM [%s] file(s) not found, cleanup not needed .", e.getMessage(), cmd.getVmName());
5900+
logger.debug(msg);
5901+
return new Answer(cmd, true, msg);
5902+
}
58895903
return new Answer(cmd, false, createLogMessageException(e, cmd));
58905904
}
58915905
}

0 commit comments

Comments
 (0)