Skip to content

Commit

Permalink
kvm: add SCSI controllers based on the number of virtio-SCSI disks (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache authored Jan 22, 2025
1 parent d053bb9 commit b186272
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,7 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
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;
}
Expand Down Expand Up @@ -2684,8 +2684,19 @@ protected ChannelDef createChannelDef(VirtualMachineTO vmTO) {
* 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ public void testCreateDevicesWithSCSIDisk() {
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);

Expand Down Expand Up @@ -640,7 +643,7 @@ public void testCreateChannelDef() {
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, "");
}
Expand Down

0 comments on commit b186272

Please sign in to comment.