Skip to content

Commit

Permalink
kvm: add SCSI controllers based on the number of virtio-SCSI disks
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Oct 17, 2024
1 parent 1af4158 commit e381ded
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,13 @@ 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));
int controllers = vmTO.getDisks().length / 7;
if (vmTO.getDisks().length % 7 != 0) {
controllers++;
}
for (int i = 0; i < controllers; i++) {
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
}
}
return devices;
}
Expand Down Expand Up @@ -2623,8 +2629,8 @@ 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);
}

protected ConsoleDef createConsoleDef() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,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 @@ -646,7 +649,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 e381ded

Please sign in to comment.