Skip to content

Commit b186272

Browse files
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). https://github.com/libvirt/libvirt/blob/50cc7a0d9d2b9df085ec073a6d60820a9642158a/src/conf/domain_conf.h#L3007-L3008 https://github.com/libvirt/libvirt/blob/50cc7a0d9d2b9df085ec073a6d60820a9642158a/src/conf/domain_conf.c#L6701-L6704
1 parent d053bb9 commit b186272

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
26462646
Map<String, String> details = vmTO.getDetails();
26472647

26482648
boolean isIothreadsEnabled = details != null && details.containsKey(VmDetailConstants.IOTHREADS);
2649-
devices.addDevice(createSCSIDef(vcpus, isIothreadsEnabled));
2649+
addSCSIControllers(devices, vcpus, vmTO.getDisks().length, isIothreadsEnabled);
26502650
}
26512651
return devices;
26522652
}
@@ -2684,8 +2684,19 @@ protected ChannelDef createChannelDef(VirtualMachineTO vmTO) {
26842684
* Creates Virtio SCSI controller. <br>
26852685
* The respective Virtio SCSI XML definition is generated only if the VM's Disk Bus is of ISCSI.
26862686
*/
2687-
protected SCSIDef createSCSIDef(int vcpus, boolean isIothreadsEnabled) {
2688-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus, isIothreadsEnabled);
2687+
protected SCSIDef createSCSIDef(short index, int vcpus, boolean isIothreadsEnabled) {
2688+
return new SCSIDef(index, 0, 0, 9 + index, 0, vcpus, isIothreadsEnabled);
2689+
}
2690+
2691+
2692+
private void addSCSIControllers(DevicesDef devices, int vcpus, int diskCount, boolean isIothreadsEnabled) {
2693+
int controllers = diskCount / 7;
2694+
if (diskCount % 7 != 0) {
2695+
controllers++;
2696+
}
2697+
for (int i = 0; i < controllers; i++) {
2698+
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
2699+
}
26892700
}
26902701

26912702
protected ConsoleDef createConsoleDef() {

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ public void testCreateDevicesWithSCSIDisk() {
453453
to.setDetails(new HashMap<>());
454454
to.setPlatformEmulator("Other PV Virtio-SCSI");
455455

456+
final DiskTO diskTO = Mockito.mock(DiskTO.class);
457+
to.setDisks(new DiskTO[]{diskTO});
458+
456459
GuestDef guest = new GuestDef();
457460
guest.setGuestType(GuestType.KVM);
458461

@@ -640,7 +643,7 @@ public void testCreateChannelDef() {
640643
public void testCreateSCSIDef() {
641644
VirtualMachineTO to = createDefaultVM(false);
642645

643-
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef(to.getCpus(), false);
646+
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef((short)0, to.getCpus(), false);
644647
Document domainDoc = parse(scsiDef.toString());
645648
verifyScsi(to, domainDoc, "");
646649
}

0 commit comments

Comments
 (0)