Skip to content

Commit 0b36a6d

Browse files
sureshanapartidhslove
authored andcommitted
VMware 80u2 and 80u3 updates/fixes (apache#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 55aa2b5 commit 0b36a6d

File tree

6 files changed

+158
-83
lines changed

6 files changed

+158
-83
lines changed

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

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

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

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

20892088
VirtualMachineDiskInfoBuilder diskInfoBuilder = null;
2090-
VirtualDevice[] nicDevices = null;
20912089
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
20922090
DiskControllerType systemVmScsiControllerType = DiskControllerType.lsilogic;
20932091
int firstScsiControllerBusNum = 0;
@@ -2104,7 +2102,6 @@ protected StartAnswer execute(StartCommand cmd) {
21042102
diskDatastores = vmMo.getAllDiskDatastores();
21052103
diskInfoBuilder = vmMo.getDiskInfoBuilder();
21062104
hasSnapshot = vmMo.hasSnapshot();
2107-
nicDevices = vmMo.getNicDevices();
21082105

21092106
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
21102107
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
@@ -2120,17 +2117,20 @@ protected StartAnswer execute(StartCommand cmd) {
21202117
}
21212118

21222119
takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
2120+
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
21232121

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

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

2131-
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
2132-
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
2133-
numScsiControllerForSystemVm, firstScsiControllerBusNum, deployAsIs);
2130+
tearDownVmDevices(vmMo, hasSnapshot, deployAsIs);
2131+
ensureDiskControllersInternal(vmMo, systemVm, controllerInfo, systemVmScsiControllerType,
2132+
numScsiControllerForSystemVm, firstScsiControllerBusNum, deployAsIs);
2133+
}
21342134
} else {
21352135
// 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).
21362136
VirtualMachineMO existingVmInDc = dcMo.findVm(vmInternalCSName);
@@ -2147,7 +2147,7 @@ protected StartAnswer execute(StartCommand cmd) {
21472147
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
21482148
if (vmMo == null) {
21492149
logger.info("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it");
2150-
vmMo = takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
2150+
takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
21512151
}
21522152
} else {
21532153
DiskTO rootDisk = null;
@@ -2257,11 +2257,11 @@ protected StartAnswer execute(StartCommand cmd) {
22572257
vmConfigSpec.setCpuHotAddEnabled(vmMo.isCpuHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm());
22582258
}
22592259

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

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

@@ -2594,7 +2594,7 @@ protected StartAnswer execute(StartCommand cmd) {
25942594

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

2597-
postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, ideControllerKey, scsiControllerKey, iqnToData, hyperHost, context);
2597+
postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, iqnToData, hyperHost, context);
25982598

25992599
//
26002600
// Power-on VM
@@ -2732,14 +2732,24 @@ private void syncVolumeDatastoreAndPathForDatastoreCluster(DiskTO vol, VirtualMa
27322732
}
27332733

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

32943304
int getReservedMemoryMb(VirtualMachineTO vmSpec) {
32953305
if (vmSpec.getDetails().get(VMwareGuru.VmwareReserveMemory.key()).equalsIgnoreCase("true")) {
3296-
if(vmSpec.getDetails().get(VmDetailConstants.RAM_RESERVATION) != null){
3306+
if (vmSpec.getDetails().get(VmDetailConstants.RAM_RESERVATION) != null) {
32973307
float reservedMemory = (vmSpec.getMaxRam() * Float.parseFloat(vmSpec.getDetails().get(VmDetailConstants.RAM_RESERVATION)));
32983308
return (int) (reservedMemory / ResourceType.bytesToMiB);
32993309
}
@@ -3631,18 +3641,18 @@ private Pair<String, String> getVMDiskInfo(String volumePath, boolean isManaged,
36313641

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

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

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

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

3678-
VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
3679-
36803688
VirtualMachineDiskInfo diskInfo = getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
3681-
assert (diskInfo != null);
3689+
if (diskInfo == null) {
3690+
continue;
3691+
}
36823692

36833693
String[] diskChain = diskInfo.getDiskChain();
3684-
assert (diskChain.length > 0);
3694+
if (diskChain.length <= 0) {
3695+
continue;
3696+
}
36853697

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

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

3693-
DatastoreFile file = new DatastoreFile(diskChain[0]);
3706+
VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
36943707

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

37093721
VolumeObjectTO volInSpec = getVolumeInSpec(vmSpec, volumeTO);
3710-
37113722
if (volInSpec != null) {
37123723
if (managed) {
37133724
Map<String, String> data = new HashMap<>();
@@ -3874,20 +3885,20 @@ private DatastoreMO getDataStoreWhereDiskExists(VmwareHypervisorHost hyperHost,
38743885
if (diskInfo != null) {
38753886
logger.info("Found existing disk info from volume path: " + volume.getPath());
38763887
return dsMo;
3877-
} else {
3878-
String chainInfo = volume.getChainInfo();
3879-
if (chainInfo != null) {
3880-
VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
3881-
if (infoInChain != null) {
3882-
String[] disks = infoInChain.getDiskChain();
3883-
if (disks.length > 0) {
3884-
for (String diskPath : disks) {
3885-
DatastoreFile file = new DatastoreFile(diskPath);
3886-
diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName);
3887-
if (diskInfo != null) {
3888-
logger.info("Found existing disk from chain info: " + diskPath);
3889-
return dsMo;
3890-
}
3888+
}
3889+
3890+
String chainInfo = volume.getChainInfo();
3891+
if (chainInfo != null) {
3892+
VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
3893+
if (infoInChain != null) {
3894+
String[] disks = infoInChain.getDiskChain();
3895+
if (disks.length > 0) {
3896+
for (String diskPath : disks) {
3897+
DatastoreFile file = new DatastoreFile(diskPath);
3898+
diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName);
3899+
if (diskInfo != null) {
3900+
logger.info("Found existing disk from chain info: " + diskPath);
3901+
return dsMo;
38913902
}
38923903
}
38933904
}
@@ -4750,7 +4761,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
47504761
Map<Integer, Long> volumeDeviceKey = new HashMap<>();
47514762
if (cmd instanceof MigrateVolumeCommand) { // Else device keys will be found in relocateVirtualMachine
47524763
MigrateVolumeCommand mcmd = (MigrateVolumeCommand) cmd;
4753-
addVolumeDiskmapping(vmMo, volumeDeviceKey, mcmd.getVolumePath(), mcmd.getVolumeId());
4764+
addVolumeDiskMapping(vmMo, volumeDeviceKey, mcmd.getVolumePath(), mcmd.getVolumeId());
47544765
if (logger.isTraceEnabled()) {
47554766
for (Integer diskId: volumeDeviceKey.keySet()) {
47564767
logger.trace(String.format("Disk to migrate has disk id %d and volumeId %d", diskId, volumeDeviceKey.get(diskId)));
@@ -4767,10 +4778,8 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
47674778
}
47684779

47694780
Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObjectToList, Command cmd, Map<Integer, Long> volumeDeviceKey) throws Exception {
4770-
List<VolumeObjectTO> volumeToList = new ArrayList<>();
4771-
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
4781+
List<VolumeObjectTO> volumeToList;
47724782
VirtualDisk[] disks = vmMo.getAllDiskDevice();
4773-
Answer answer;
47744783
if (logger.isTraceEnabled()) {
47754784
logger.trace(String.format("creating answer for %s", cmd.getClass().getSimpleName()));
47764785
}
@@ -4787,7 +4796,7 @@ Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObje
47874796
return new Answer(cmd, false, null);
47884797
}
47894798

4790-
private void addVolumeDiskmapping(VirtualMachineMO vmMo, Map<Integer, Long> volumeDeviceKey, String volumePath, long volumeId) throws Exception {
4799+
private void addVolumeDiskMapping(VirtualMachineMO vmMo, Map<Integer, Long> volumeDeviceKey, String volumePath, long volumeId) throws Exception {
47914800
if (logger.isDebugEnabled()) {
47924801
logger.debug(String.format("locating disk for volume (%d) using path %s", volumeId, volumePath));
47934802
}
@@ -4922,7 +4931,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
49224931
VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster;
49234932
String targetDsName = cmd.getTargetPool().getUuid();
49244933
morDestinationDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(dsHost, targetDsName);
4925-
if(morDestinationDS == null) {
4934+
if (morDestinationDS == null) {
49264935
String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost.getHyperHostName();
49274936
logger.error(msg);
49284937
throw new CloudRuntimeException(msg);
@@ -5889,6 +5898,11 @@ protected Answer execute(CleanupVMCommand cmd) {
58895898
s_logger.debug(msg);
58905899
return new Answer(cmd, true, msg);
58915900
} catch (Exception e) {
5901+
if (e.getMessage().contains("was not found")) {
5902+
String msg = String.format("%s - VM [%s] file(s) not found, cleanup not needed .", e.getMessage(), cmd.getVmName());
5903+
logger.debug(msg);
5904+
return new Answer(cmd, true, msg);
5905+
}
58925906
return new Answer(cmd, false, createLogMessageException(e, cmd));
58935907
}
58945908
}

0 commit comments

Comments
 (0)