Skip to content

Commit a3bb84b

Browse files
authored
[VMware] Update SCSI controllers for VMs (apache#5910)
1 parent 122b018 commit a3bb84b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,14 @@ protected void ensureDiskControllers(VirtualMachineMO vmMo, Pair<String, String>
18131813
int requiredNumScsiControllers = VmwareHelper.MAX_SCSI_CONTROLLER_COUNT - scsiControllerInfo.first();
18141814
int availableBusNum = scsiControllerInfo.second() + 1; // method returned current max. bus number
18151815

1816+
if (DiskControllerType.getType(scsiDiskController) != scsiControllerInfo.third()) {
1817+
s_logger.debug(String.format("Change controller type from: %s to: %s", scsiControllerInfo.third().toString(),
1818+
scsiDiskController));
1819+
vmMo.tearDownDevices(new Class<?>[]{VirtualSCSIController.class});
1820+
vmMo.addScsiDeviceControllers(DiskControllerType.getType(scsiDiskController));
1821+
return;
1822+
}
1823+
18161824
if (requiredNumScsiControllers == 0) {
18171825
return;
18181826
}

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,41 @@ public int getPvScsiDeviceControllerKey() throws Exception {
22932293
throw new Exception("VMware Paravirtual SCSI Controller Not Found");
22942294
}
22952295

2296+
protected VirtualSCSIController getScsiController(DiskControllerType type) {
2297+
switch (type) {
2298+
case pvscsi:
2299+
return new ParaVirtualSCSIController();
2300+
case lsisas1068:
2301+
return new VirtualLsiLogicSASController();
2302+
case buslogic:
2303+
return new VirtualBusLogicController();
2304+
default:
2305+
return new VirtualLsiLogicController();
2306+
}
2307+
}
2308+
2309+
public void addScsiDeviceControllers(DiskControllerType type) throws Exception {
2310+
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
2311+
int busNum = 0;
2312+
while (busNum < VmwareHelper.MAX_SCSI_CONTROLLER_COUNT) {
2313+
VirtualSCSIController scsiController = getScsiController(type);
2314+
scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
2315+
scsiController.setBusNumber(busNum);
2316+
scsiController.setKey(busNum - VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
2317+
VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
2318+
scsiControllerSpec.setDevice(scsiController);
2319+
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
2320+
vmConfig.getDeviceChange().add(scsiControllerSpec);
2321+
busNum++;
2322+
}
2323+
2324+
if (configureVm(vmConfig)) {
2325+
s_logger.info("Successfully added SCSI controllers.");
2326+
} else {
2327+
throw new Exception("Unable to add Scsi controllers to the VM " + getName());
2328+
}
2329+
}
2330+
22962331
public void ensurePvScsiDeviceController(int requiredNumScsiControllers, int availableBusNum) throws Exception {
22972332
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
22982333

0 commit comments

Comments
 (0)