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>
This commit is contained in:
Suresh Kumar Anaparti 2024-04-18 18:21:17 +05:30 committed by GitHub
parent 7de8a6d082
commit dfd5158d67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 3 deletions

View File

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

View File

@ -596,6 +596,22 @@ public class LibvirtVMDef {
public QemuObject.EncryptFormat getEncryptFormat() { return this.encryptFormat; } 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 { public enum DeviceType {
FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun"); FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun");
String _type; String _type;
@ -747,6 +763,7 @@ public class LibvirtVMDef {
private boolean isIothreadsEnabled; private boolean isIothreadsEnabled;
private BlockIOSize logicalBlockIOSize = null; private BlockIOSize logicalBlockIOSize = null;
private BlockIOSize physicalBlockIOSize = null; private BlockIOSize physicalBlockIOSize = null;
private DiskGeometry geometry = null;
public DiscardType getDiscard() { public DiscardType getDiscard() {
return _discard; return _discard;
@ -1087,9 +1104,20 @@ public class LibvirtVMDef {
this._serial = serial; 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;
}
public String getSourceHost() { public String getSourceHost() {
return _sourceHost; return _sourceHost;
@ -1174,6 +1202,10 @@ public class LibvirtVMDef {
} }
diskBuilder.append("/>\n"); diskBuilder.append("/>\n");
if (geometry != null) {
diskBuilder.append(geometry.toXml());
}
if (logicalBlockIOSize != null || physicalBlockIOSize != null) { if (logicalBlockIOSize != null || physicalBlockIOSize != null) {
diskBuilder.append("<blockio "); diskBuilder.append("<blockio ");
if (logicalBlockIOSize != null) { if (logicalBlockIOSize != null) {

View File

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

View File

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

View File

@ -317,6 +317,20 @@ public class LibvirtVMDefTest extends TestCase {
assertEquals(expectedXml, disk.toString()); 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 @Test
public void testDiskDefWithMultipleHosts() { public void testDiskDefWithMultipleHosts() {
String path = "/mnt/primary1"; String path = "/mnt/primary1";