Skip to content

Commit c4a266a

Browse files
nvazquezdhslove
authored andcommitted
Support virtio-blk root disk controller (apache#10229)
1 parent 026d015 commit c4a266a

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
34683468
disk.setLogicalBlockIOSize(pool.getSupportedLogicalBlockSize());
34693469
disk.setPhysicalBlockIOSize(pool.getSupportedPhysicalBlockSize());
34703470

3471-
if (diskBusType == DiskDef.DiskBus.SCSI ) {
3471+
if (diskBusType == DiskDef.DiskBus.SCSI || diskBusType == DiskDef.DiskBus.VIRTIOBLK) {
34723472
disk.setQemuDriver(true);
34733473
disk.setDiscard(DiscardType.UNMAP);
34743474
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ public String toString() {
708708
}
709709

710710
public enum DiskBus {
711-
IDE("ide"), SCSI("scsi"), VIRTIO("virtio"), XEN("xen"), USB("usb"), UML("uml"), FDC("fdc"), SATA("sata");
711+
IDE("ide"), SCSI("scsi"), VIRTIO("virtio"), XEN("xen"), USB("usb"), UML("uml"), FDC("fdc"), SATA("sata"), VIRTIOBLK("virtio-blk");
712712
String _bus;
713713

714714
DiskBus(String bus) {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,12 +1473,14 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
14731473
if (disk.getDeviceType() == DeviceType.DISK) {
14741474
if (disk.getBusType() == DiskDef.DiskBus.SCSI) {
14751475
busT = DiskDef.DiskBus.SCSI;
1476+
} else if (disk.getBusType() == DiskDef.DiskBus.VIRTIOBLK) {
1477+
busT = DiskDef.DiskBus.VIRTIOBLK;
14761478
}
14771479
break;
14781480
}
14791481
}
14801482
diskdef = new DiskDef();
1481-
if (busT == DiskDef.DiskBus.SCSI) {
1483+
if (busT == DiskDef.DiskBus.SCSI || busT == DiskDef.DiskBus.VIRTIOBLK) {
14821484
diskdef.setQemuDriver(true);
14831485
diskdef.setDiscard(DiscardType.UNMAP);
14841486
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6531,4 +6531,14 @@ public void createLinstorVdb() throws LibvirtException, InternalErrorException,
65316531
assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard());
65326532
}
65336533
}
6534+
6535+
@Test
6536+
public void testGetDiskModelFromVMDetailVirtioBlk() {
6537+
VirtualMachineTO virtualMachineTO = Mockito.mock(VirtualMachineTO.class);
6538+
Map<String, String> details = new HashMap<>();
6539+
details.put(VmDetailConstants.ROOT_DISK_CONTROLLER, "virtio-blk");
6540+
Mockito.when(virtualMachineTO.getDetails()).thenReturn(details);
6541+
DiskDef.DiskBus diskBus = libvirtComputingResourceSpy.getDiskModelFromVMDetail(virtualMachineTO);
6542+
assertEquals(DiskDef.DiskBus.VIRTIOBLK, diskBus);
6543+
}
65346544
}

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5129,8 +5129,8 @@ private void fillVMOrTemplateDetailOptions(final Map<String, List<String>> optio
51295129
if (HypervisorType.KVM.equals(hypervisorType)) {
51305130
options.put(VmDetailConstants.CPU_THREAD_PER_CORE, Collections.emptyList());
51315131
options.put(VmDetailConstants.NIC_ADAPTER, Arrays.asList("e1000", "virtio", "rtl8139", "vmxnet3", "ne2k_pci"));
5132-
options.put(VmDetailConstants.ROOT_DISK_CONTROLLER, Arrays.asList("osdefault", "ide", "scsi", "virtio"));
5133-
options.put(VmDetailConstants.DATA_DISK_CONTROLLER, Arrays.asList("osdefault", "ide", "scsi", "virtio"));
5132+
options.put(VmDetailConstants.ROOT_DISK_CONTROLLER, Arrays.asList("osdefault", "ide", "scsi", "virtio", "virtio-blk"));
5133+
options.put(VmDetailConstants.DATA_DISK_CONTROLLER, Arrays.asList("osdefault", "ide", "scsi", "virtio", "virtio-blk"));
51345134
options.put(VmDetailConstants.SOUND, Arrays.asList("ich6"));
51355135
options.put(VmDetailConstants.VIDEO_HARDWARE, Arrays.asList("cirrus", "vga", "qxl", "virtio"));
51365136
options.put(VmDetailConstants.VIDEO_HARDWARE_2, Arrays.asList("virtio"));

0 commit comments

Comments
 (0)