kvm: add SCSI controllers based on the number of virtio-SCSI disks (#9823)

According to libvirt code, the units per scsi controller is set to 7
therefore, we need to create scsi controller every 7 disks (including CDROM).

50cc7a0d9d/src/conf/domain_conf.h (L3007-L3008)

50cc7a0d9d/src/conf/domain_conf.c (L6701-L6704)
This commit is contained in:
Wei Zhou 2025-01-22 14:00:02 +01:00 committed by GitHub
parent d053bb97ec
commit b186272f68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -2646,7 +2646,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
Map<String, String> details = vmTO.getDetails();
boolean isIothreadsEnabled = details != null && details.containsKey(VmDetailConstants.IOTHREADS);
devices.addDevice(createSCSIDef(vcpus, isIothreadsEnabled));
addSCSIControllers(devices, vcpus, vmTO.getDisks().length, isIothreadsEnabled);
}
return devices;
}
@ -2684,8 +2684,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
* Creates Virtio SCSI controller. <br>
* The respective Virtio SCSI XML definition is generated only if the VM's Disk Bus is of ISCSI.
*/
protected SCSIDef createSCSIDef(int vcpus, boolean isIothreadsEnabled) {
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus, isIothreadsEnabled);
protected SCSIDef createSCSIDef(short index, int vcpus, boolean isIothreadsEnabled) {
return new SCSIDef(index, 0, 0, 9 + index, 0, vcpus, isIothreadsEnabled);
}
private void addSCSIControllers(DevicesDef devices, int vcpus, int diskCount, boolean isIothreadsEnabled) {
int controllers = diskCount / 7;
if (diskCount % 7 != 0) {
controllers++;
}
for (int i = 0; i < controllers; i++) {
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
}
}
protected ConsoleDef createConsoleDef() {

View File

@ -453,6 +453,9 @@ public class LibvirtComputingResourceTest {
to.setDetails(new HashMap<>());
to.setPlatformEmulator("Other PV Virtio-SCSI");
final DiskTO diskTO = Mockito.mock(DiskTO.class);
to.setDisks(new DiskTO[]{diskTO});
GuestDef guest = new GuestDef();
guest.setGuestType(GuestType.KVM);
@ -640,7 +643,7 @@ public class LibvirtComputingResourceTest {
public void testCreateSCSIDef() {
VirtualMachineTO to = createDefaultVM(false);
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef(to.getCpus(), false);
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef((short)0, to.getCpus(), false);
Document domainDoc = parse(scsiDef.toString());
verifyScsi(to, domainDoc, "");
}