mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
7de8a6d082
commit
dfd5158d67
@ -3137,7 +3137,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pool.customizeLibvirtDiskDef(disk);
|
||||
}
|
||||
|
||||
if (data instanceof VolumeObjectTO) {
|
||||
@ -3512,6 +3512,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
|
||||
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
|
||||
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
|
||||
attachingPool.customizeLibvirtDiskDef(diskdef);
|
||||
}
|
||||
|
||||
final String xml = diskdef.toString();
|
||||
|
||||
@ -596,6 +596,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;
|
||||
@ -747,6 +763,7 @@ public class LibvirtVMDef {
|
||||
private boolean isIothreadsEnabled;
|
||||
private BlockIOSize logicalBlockIOSize = null;
|
||||
private BlockIOSize physicalBlockIOSize = null;
|
||||
private DiskGeometry geometry = null;
|
||||
|
||||
public DiscardType getDiscard() {
|
||||
return _discard;
|
||||
@ -1087,9 +1104,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;
|
||||
}
|
||||
|
||||
public String getSourceHost() {
|
||||
return _sourceHost;
|
||||
@ -1174,6 +1202,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) {
|
||||
|
||||
@ -108,4 +108,7 @@ public interface KVMStoragePool {
|
||||
default LibvirtVMDef.DiskDef.BlockIOSize getSupportedPhysicalBlockSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default void customizeLibvirtDiskDef(LibvirtVMDef.DiskDef disk) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -1484,6 +1484,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
}
|
||||
diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize());
|
||||
diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize());
|
||||
attachingPool.customizeLibvirtDiskDef(diskdef);
|
||||
}
|
||||
|
||||
attachOrDetachDevice(conn, attach, vmName, diskdef, waitDetachDevice);
|
||||
|
||||
@ -317,6 +317,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";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user