Skip to content

Commit e381ded

Browse files
committed
kvm: add SCSI controllers based on the number of virtio-SCSI disks
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 1af4158 commit e381ded

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

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

25872587
boolean isIothreadsEnabled = details != null && details.containsKey(VmDetailConstants.IOTHREADS);
2588-
devices.addDevice(createSCSIDef(vcpus, isIothreadsEnabled));
2588+
int controllers = vmTO.getDisks().length / 7;
2589+
if (vmTO.getDisks().length % 7 != 0) {
2590+
controllers++;
2591+
}
2592+
for (int i = 0; i < controllers; i++) {
2593+
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
2594+
}
25892595
}
25902596
return devices;
25912597
}
@@ -2623,8 +2629,8 @@ protected ChannelDef createChannelDef(VirtualMachineTO vmTO) {
26232629
* Creates Virtio SCSI controller. <br>
26242630
* The respective Virtio SCSI XML definition is generated only if the VM's Disk Bus is of ISCSI.
26252631
*/
2626-
protected SCSIDef createSCSIDef(int vcpus, boolean isIothreadsEnabled) {
2627-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus, isIothreadsEnabled);
2632+
protected SCSIDef createSCSIDef(short index, int vcpus, boolean isIothreadsEnabled) {
2633+
return new SCSIDef(index, 0, 0, 9 + index, 0, vcpus, isIothreadsEnabled);
26282634
}
26292635

26302636
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
@@ -459,6 +459,9 @@ public void testCreateDevicesWithSCSIDisk() {
459459
to.setDetails(new HashMap<>());
460460
to.setPlatformEmulator("Other PV Virtio-SCSI");
461461

462+
final DiskTO diskTO = Mockito.mock(DiskTO.class);
463+
to.setDisks(new DiskTO[]{diskTO});
464+
462465
GuestDef guest = new GuestDef();
463466
guest.setGuestType(GuestType.KVM);
464467

@@ -646,7 +649,7 @@ public void testCreateChannelDef() {
646649
public void testCreateSCSIDef() {
647650
VirtualMachineTO to = createDefaultVM(false);
648651

649-
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef(to.getCpus(), false);
652+
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef((short)0, to.getCpus(), false);
650653
Document domainDoc = parse(scsiDef.toString());
651654
verifyScsi(to, domainDoc, "");
652655
}

0 commit comments

Comments
 (0)