Skip to content

Commit 9b3acae

Browse files
weizhouapachejschoiRR
authored andcommitted
kvm: add SCSI controllers based on the number of virtio-SCSI disks (apache#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 97b01ac commit 9b3acae

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,9 +2919,7 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
29192919

29202920
int socket = getCoresPerSocket(vcpus, details);
29212921
boolean isIothreadsEnabled = details != null && details.containsKey(VmDetailConstants.IOTHREADS);
2922-
for (int i = 0; i < socket; i++) {
2923-
devices.addDevice(createSCSIDef(i, i, vcpus, isIothreadsEnabled));
2924-
}
2922+
addSCSIControllers(devices, vcpus, vmTO.getDisks().length, isIothreadsEnabled);
29252923
}
29262924

29272925

@@ -2982,20 +2980,19 @@ protected ChannelDef createChannelDef(VirtualMachineTO vmTO) {
29822980
* Creates Virtio SCSI controller. <br>
29832981
* The respective Virtio SCSI XML definition is generated only if the VM's Disk Bus is of ISCSI.
29842982
*/
2985-
protected SCSIDef createSCSIDef(int index, int function ,int vcpus) {
2986-
return new SCSIDef((short)index, 0, 0, 9, function, vcpus);
2987-
}
2988-
2989-
protected SCSIDef createSCSIDef(int vcpus) {
2990-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus);
2983+
protected SCSIDef createSCSIDef(short index, int vcpus, boolean isIothreadsEnabled) {
2984+
return new SCSIDef(index, 0, 0, 9 + index, 0, vcpus, isIothreadsEnabled);
29912985
}
29922986

2993-
protected SCSIDef createSCSIDef(int index, int function, int vcpus, boolean isIothreadsEnabled) {
2994-
return new SCSIDef((short)index, 0, 0, 9, function, vcpus, isIothreadsEnabled);
2995-
}
29962987

2997-
protected SCSIDef createSCSIDef(int vcpus, boolean isIothreadsEnabled) {
2998-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus, isIothreadsEnabled);
2988+
private void addSCSIControllers(DevicesDef devices, int vcpus, int diskCount, boolean isIothreadsEnabled) {
2989+
int controllers = diskCount / 7;
2990+
if (diskCount % 7 != 0) {
2991+
controllers++;
2992+
}
2993+
for (int i = 0; i < controllers; i++) {
2994+
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
2995+
}
29992996
}
30002997

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

464+
final DiskTO diskTO = Mockito.mock(DiskTO.class);
465+
to.setDisks(new DiskTO[]{diskTO});
466+
464467
GuestDef guest = new GuestDef();
465468
guest.setGuestType(GuestType.KVM);
466469

@@ -648,7 +651,7 @@ public void testCreateChannelDef() {
648651
public void testCreateSCSIDef() {
649652
VirtualMachineTO to = createDefaultVM(false);
650653

651-
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef(to.getCpus(), false);
654+
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef((short)0, to.getCpus(), false);
652655
Document domainDoc = parse(scsiDef.toString());
653656
verifyScsi(to, domainDoc, "");
654657
}

0 commit comments

Comments
 (0)