Skip to content

Commit 4e15e51

Browse files
weizhouapachedhslove
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 3486f15 commit 4e15e51

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
@@ -2911,9 +2911,7 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
29112911

29122912
int socket = getCoresPerSocket(vcpus, details);
29132913
boolean isIothreadsEnabled = details != null && details.containsKey(VmDetailConstants.IOTHREADS);
2914-
for (int i = 0; i < socket; i++) {
2915-
devices.addDevice(createSCSIDef(i, i, vcpus, isIothreadsEnabled));
2916-
}
2914+
addSCSIControllers(devices, vcpus, vmTO.getDisks().length, isIothreadsEnabled);
29172915
}
29182916

29192917

@@ -2974,20 +2972,19 @@ protected ChannelDef createChannelDef(VirtualMachineTO vmTO) {
29742972
* Creates Virtio SCSI controller. <br>
29752973
* The respective Virtio SCSI XML definition is generated only if the VM's Disk Bus is of ISCSI.
29762974
*/
2977-
protected SCSIDef createSCSIDef(int index, int function ,int vcpus) {
2978-
return new SCSIDef((short)index, 0, 0, 9, function, vcpus);
2979-
}
2980-
2981-
protected SCSIDef createSCSIDef(int vcpus) {
2982-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus);
2975+
protected SCSIDef createSCSIDef(short index, int vcpus, boolean isIothreadsEnabled) {
2976+
return new SCSIDef(index, 0, 0, 9 + index, 0, vcpus, isIothreadsEnabled);
29832977
}
29842978

2985-
protected SCSIDef createSCSIDef(int index, int function, int vcpus, boolean isIothreadsEnabled) {
2986-
return new SCSIDef((short)index, 0, 0, 9, function, vcpus, isIothreadsEnabled);
2987-
}
29882979

2989-
protected SCSIDef createSCSIDef(int vcpus, boolean isIothreadsEnabled) {
2990-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus, isIothreadsEnabled);
2980+
private void addSCSIControllers(DevicesDef devices, int vcpus, int diskCount, boolean isIothreadsEnabled) {
2981+
int controllers = diskCount / 7;
2982+
if (diskCount % 7 != 0) {
2983+
controllers++;
2984+
}
2985+
for (int i = 0; i < controllers; i++) {
2986+
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
2987+
}
29912988
}
29922989

29932990
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)