Allow kvm storage plugin to customize diskdef, add geometry (#402)

* Allow kvm storage plugin to customize diskdef, add geometry

* formatting update

---------

Co-authored-by: Marcus Sorensen <mls@apple.com>
Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com>
This commit is contained in:
Marcus Sorensen 2024-04-08 08:28:59 -07:00 committed by GitHub
parent f896586925
commit 631b0960f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 3 deletions

View File

@ -3081,7 +3081,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
pool.customizeLibvirtDiskDef(disk);
}
if (data instanceof VolumeObjectTO) {
@ -3452,6 +3452,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
attachingPool.customizeLibvirtDiskDef(diskdef);
}
final String xml = diskdef.toString();

View File

@ -595,6 +595,22 @@ public class LibvirtVMDef {
public QemuObject.EncryptFormat getEncryptFormat() { return this.encryptFormat; }
}
public static class DiskGeometry {
int cylinders;
int heads;
int sectors;
public DiskGeometry(int cylinders, int heads, int sectors) {
this.cylinders = cylinders;
this.heads = heads;
this.sectors = sectors;
}
public String toXml() {
return String.format("<geometry cyls='%d' heads='%d' secs='%d'/>\n", this.cylinders, this.heads, this.sectors);
}
}
public enum DeviceType {
FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun");
String _type;
@ -746,6 +762,7 @@ public class LibvirtVMDef {
private boolean isIothreadsEnabled;
private BlockIOSize logicalBlockIOSize = null;
private BlockIOSize physicalBlockIOSize = null;
private DiskGeometry geometry = null;
public DiscardType getDiscard() {
return _discard;
@ -1086,9 +1103,20 @@ public class LibvirtVMDef {
this._serial = serial;
}
public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details) { this.encryptDetails = details; }
public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details)
{
this.encryptDetails = details;
}
public LibvirtDiskEncryptDetails getLibvirtDiskEncryptDetails() { return this.encryptDetails; }
public LibvirtDiskEncryptDetails getLibvirtDiskEncryptDetails()
{
return this.encryptDetails;
}
public void setGeometry(DiskGeometry geometry)
{
this.geometry = geometry;
}
@Override
public String toString() {
@ -1161,6 +1189,10 @@ public class LibvirtVMDef {
}
diskBuilder.append("/>\n");
if (geometry != null) {
diskBuilder.append(geometry.toXml());
}
if (logicalBlockIOSize != null || physicalBlockIOSize != null) {
diskBuilder.append("<blockio ");
if (logicalBlockIOSize != null) {

View File

@ -83,4 +83,7 @@ public interface KVMStoragePool {
default LibvirtVMDef.DiskDef.BlockIOSize getSupportedPhysicalBlockSize() {
return null;
}
default void customizeLibvirtDiskDef(LibvirtVMDef.DiskDef disk) {
}
}

View File

@ -1464,6 +1464,7 @@ public class KVMStorageProcessor implements StorageProcessor {
}
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
attachingPool.customizeLibvirtDiskDef(diskdef);
}
attachOrDetachDevice(conn, attach, vmName, diskdef, waitDetachDevice);

View File

@ -276,6 +276,20 @@ public class LibvirtVMDefTest extends TestCase {
assertEquals(expectedXml, disk.toString());
}
@Test
public void testDiskDefWithGeometry() {
DiskDef disk = new DiskDef();
disk.defBlockBasedDisk("disk1", 1, DiskDef.DiskBus.VIRTIO);
disk.setGeometry(new DiskDef.DiskGeometry(16383, 16, 63));
String expectedXML = "<disk device='disk' type='block'>\n" +
"<driver name='qemu' type='raw' cache='none' />\n" +
"<source dev='disk1'/>\n" +
"<target dev='vdb' bus='virtio'/>\n" +
"<geometry cyls='16383' heads='16' secs='63'/>\n" +
"</disk>\n";
assertEquals(expectedXML, disk.toString());
}
@Test
public void testDiskDefWithMultipleHosts() {
String path = "/mnt/primary1";