Skip to content

Commit

Permalink
Allow kvm storage plugin to customize diskdef, add geometry (apache#8839
Browse files Browse the repository at this point in the history
)

* Allow kvm storage plugin to customize diskdef, add geometry

* formatting update

---------

Co-authored-by: Marcus Sorensen <[email protected]>
  • Loading branch information
sureshanaparti and Marcus Sorensen authored Apr 18, 2024
1 parent 7de8a6d commit dfd5158
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3137,7 +3137,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
}

}

pool.customizeLibvirtDiskDef(disk);
}

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

diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
attachingPool.customizeLibvirtDiskDef(diskdef);
}

final String xml = diskdef.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,22 @@ public LibvirtDiskEncryptDetails(String passphraseUuid, QemuObject.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 {
FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun");
String _type;
Expand Down Expand Up @@ -747,6 +763,7 @@ public String toString() {
private boolean isIothreadsEnabled;
private BlockIOSize logicalBlockIOSize = null;
private BlockIOSize physicalBlockIOSize = null;
private DiskGeometry geometry = null;

public DiscardType getDiscard() {
return _discard;
Expand Down Expand Up @@ -1087,9 +1104,20 @@ public void setSerial(String 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() {
return _sourceHost;
Expand Down Expand Up @@ -1174,6 +1202,10 @@ public String toString() {
}
diskBuilder.append("/>\n");

if (geometry != null) {
diskBuilder.append(geometry.toXml());
}

if (logicalBlockIOSize != null || physicalBlockIOSize != null) {
diskBuilder.append("<blockio ");
if (logicalBlockIOSize != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,7 @@ default LibvirtVMDef.DiskDef.BlockIOSize getSupportedLogicalBlockSize() {
default LibvirtVMDef.DiskDef.BlockIOSize getSupportedPhysicalBlockSize() {
return null;
}

default void customizeLibvirtDiskDef(LibvirtVMDef.DiskDef disk) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
}
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
attachingPool.customizeLibvirtDiskDef(diskdef);
}

attachOrDetachDevice(conn, attach, vmName, diskdef, waitDetachDevice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ public void testDiskDefWithBlockIO() {
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";
Expand Down

0 comments on commit dfd5158

Please sign in to comment.