Skip to content

Commit dfd5158

Browse files
sureshanapartiMarcus Sorensen
andauthored
Allow kvm storage plugin to customize diskdef, add geometry (#8839)
* Allow kvm storage plugin to customize diskdef, add geometry * formatting update --------- Co-authored-by: Marcus Sorensen <mls@apple.com>
1 parent 7de8a6d commit dfd5158

5 files changed

Lines changed: 54 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3137,7 +3137,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
31373137
}
31383138

31393139
}
3140-
3140+
pool.customizeLibvirtDiskDef(disk);
31413141
}
31423142

31433143
if (data instanceof VolumeObjectTO) {
@@ -3512,6 +3512,7 @@ public synchronized String attachOrDetachDisk(final Connect conn,
35123512

35133513
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
35143514
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
3515+
attachingPool.customizeLibvirtDiskDef(diskdef);
35153516
}
35163517

35173518
final String xml = diskdef.toString();

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,22 @@ public LibvirtDiskEncryptDetails(String passphraseUuid, QemuObject.EncryptFormat
596596
public QemuObject.EncryptFormat getEncryptFormat() { return this.encryptFormat; }
597597
}
598598

599+
public static class DiskGeometry {
600+
int cylinders;
601+
int heads;
602+
int sectors;
603+
604+
public DiskGeometry(int cylinders, int heads, int sectors) {
605+
this.cylinders = cylinders;
606+
this.heads = heads;
607+
this.sectors = sectors;
608+
}
609+
610+
public String toXml() {
611+
return String.format("<geometry cyls='%d' heads='%d' secs='%d'/>\n", this.cylinders, this.heads, this.sectors);
612+
}
613+
}
614+
599615
public enum DeviceType {
600616
FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun");
601617
String _type;
@@ -747,6 +763,7 @@ public String toString() {
747763
private boolean isIothreadsEnabled;
748764
private BlockIOSize logicalBlockIOSize = null;
749765
private BlockIOSize physicalBlockIOSize = null;
766+
private DiskGeometry geometry = null;
750767

751768
public DiscardType getDiscard() {
752769
return _discard;
@@ -1087,9 +1104,20 @@ public void setSerial(String serial) {
10871104
this._serial = serial;
10881105
}
10891106

1090-
public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details) { this.encryptDetails = details; }
1107+
public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details)
1108+
{
1109+
this.encryptDetails = details;
1110+
}
1111+
1112+
public LibvirtDiskEncryptDetails getLibvirtDiskEncryptDetails()
1113+
{
1114+
return this.encryptDetails;
1115+
}
10911116

1092-
public LibvirtDiskEncryptDetails getLibvirtDiskEncryptDetails() { return this.encryptDetails; }
1117+
public void setGeometry(DiskGeometry geometry)
1118+
{
1119+
this.geometry = geometry;
1120+
}
10931121

10941122
public String getSourceHost() {
10951123
return _sourceHost;
@@ -1174,6 +1202,10 @@ public String toString() {
11741202
}
11751203
diskBuilder.append("/>\n");
11761204

1205+
if (geometry != null) {
1206+
diskBuilder.append(geometry.toXml());
1207+
}
1208+
11771209
if (logicalBlockIOSize != null || physicalBlockIOSize != null) {
11781210
diskBuilder.append("<blockio ");
11791211
if (logicalBlockIOSize != null) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,7 @@ default LibvirtVMDef.DiskDef.BlockIOSize getSupportedLogicalBlockSize() {
108108
default LibvirtVMDef.DiskDef.BlockIOSize getSupportedPhysicalBlockSize() {
109109
return null;
110110
}
111+
112+
default void customizeLibvirtDiskDef(LibvirtVMDef.DiskDef disk) {
113+
}
111114
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
14841484
}
14851485
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
14861486
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
1487+
attachingPool.customizeLibvirtDiskDef(diskdef);
14871488
}
14881489

14891490
attachOrDetachDevice(conn, attach, vmName, diskdef, waitDetachDevice);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,20 @@ public void testDiskDefWithBlockIO() {
317317
assertEquals(expectedXml, disk.toString());
318318
}
319319

320+
@Test
321+
public void testDiskDefWithGeometry() {
322+
DiskDef disk = new DiskDef();
323+
disk.defBlockBasedDisk("disk1", 1, DiskDef.DiskBus.VIRTIO);
324+
disk.setGeometry(new DiskDef.DiskGeometry(16383, 16, 63));
325+
String expectedXML = "<disk device='disk' type='block'>\n" +
326+
"<driver name='qemu' type='raw' cache='none' />\n" +
327+
"<source dev='disk1'/>\n" +
328+
"<target dev='vdb' bus='virtio'/>\n" +
329+
"<geometry cyls='16383' heads='16' secs='63'/>\n" +
330+
"</disk>\n";
331+
assertEquals(expectedXML, disk.toString());
332+
}
333+
320334
@Test
321335
public void testDiskDefWithMultipleHosts() {
322336
String path = "/mnt/primary1";

0 commit comments

Comments
 (0)