diff options
author | Simon Rettberg | 2023-06-26 12:19:05 +0200 |
---|---|---|
committer | Simon Rettberg | 2023-06-26 12:19:05 +0200 |
commit | 41126d5da4a87320407885cf2a5eedc1c828dfaa (patch) | |
tree | b8e041a9c1985510b98447185555081215e925e0 /src | |
parent | [thrift] Ignore yet another socket exception (diff) | |
download | master-sync-shared-41126d5da4a87320407885cf2a5eedc1c828dfaa.tar.gz master-sync-shared-41126d5da4a87320407885cf2a5eedc1c828dfaa.tar.xz master-sync-shared-41126d5da4a87320407885cf2a5eedc1c828dfaa.zip |
[libvirt] Allow setting PCI address on Device level
Devices like video and disk can be PCI Devices and thus have an
<address> tag that defines where on the PCI bus it sits. Move the
according helper functions for getting/setting this address from
HostDevPci up to Device.
Diffstat (limited to 'src')
4 files changed, 70 insertions, 56 deletions
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Device.java b/src/main/java/org/openslx/libvirt/domain/device/Device.java index 1e0e031..31a54ca 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Device.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Device.java @@ -11,7 +11,7 @@ import org.w3c.dom.Node; * @author Manuel Bentele * @version 1.0 */ -public class Device extends LibvirtXmlNode +public class Device extends LibvirtXmlNode implements HostdevAddressableTarget<HostdevPciDeviceAddress> { /** * Creates an empty virtual machine device. @@ -171,6 +171,63 @@ public class Device extends LibvirtXmlNode } /** + * Sets the PCI device address for an XML address element selected by a XPath expression. + * + * @param expression XPath expression to select the XML address element. + * @param address PCI device address for the selected XML address element. + */ + protected void setPciAddress( final String expression, final HostdevPciDeviceAddress address ) + { + final String pciDomain = HostdevUtils.appendHexPrefix( address.getPciDomainAsString() ); + final String pciBus = HostdevUtils.appendHexPrefix( address.getPciBusAsString() ); + final String pciDevice = HostdevUtils.appendHexPrefix( address.getPciDeviceAsString() ); + final String pciFunction = HostdevUtils.appendHexPrefix( address.getPciFunctionAsString() ); + + this.setXmlElementAttributeValue( expression, "domain", pciDomain ); + this.setXmlElementAttributeValue( expression, "bus", pciBus ); + this.setXmlElementAttributeValue( expression, "slot", pciDevice ); + this.setXmlElementAttributeValue( expression, "function", pciFunction ); + } + + /** + * Returns the PCI device address from an address XML element selected by a XPath expression. + * + * @param expression XPath expression to select the XML address element. + * @return PCI device address from the selected XML address element. + */ + protected HostdevPciDeviceAddress getPciAddress( final String expression ) + { + String pciDomain = this.getXmlElementAttributeValue( expression, "domain" ); + String pciBus = this.getXmlElementAttributeValue( expression, "bus" ); + String pciDevice = this.getXmlElementAttributeValue( expression, "slot" ); + String pciFunction = this.getXmlElementAttributeValue( expression, "function" ); + + pciDomain = HostdevUtils.removeHexPrefix( pciDomain ); + pciBus = HostdevUtils.removeHexPrefix( pciBus ); + pciDevice = HostdevUtils.removeHexPrefix( pciDevice ); + pciFunction = HostdevUtils.removeHexPrefix( pciFunction ); + + return HostdevPciDeviceAddress.valueOf( pciDomain + ":" + pciBus + ":" + pciDevice + "." + pciFunction ); + } + + /** + * Returns this devices PCI bus address, or null if it doesn't have an explicit one + * set, or if the address type isn't PCI. + */ + public HostdevPciDeviceAddress getPciTarget() + { + if ( !"pci".equals( this.getXmlElementAttributeValue( "address", "type" ) ) ) + return null; + return this.getPciAddress( "address" ); + } + + public void setPciTarget( HostdevPciDeviceAddress address ) + { + this.setPciAddress( "address", address ); + this.setXmlElementAttributeValue( "address", "type", "pci" ); + } + + /** * Type of virtual machine devices. * * @author Manuel Bentele diff --git a/src/main/java/org/openslx/libvirt/domain/device/HostdevAddressableTarget.java b/src/main/java/org/openslx/libvirt/domain/device/HostdevAddressableTarget.java index 8a6f9a1..ca06065 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/HostdevAddressableTarget.java +++ b/src/main/java/org/openslx/libvirt/domain/device/HostdevAddressableTarget.java @@ -15,12 +15,12 @@ public abstract interface HostdevAddressableTarget<T> * * @return target of the target device (in the virtual machine). */ - public T getTarget(); + public T getPciTarget(); /** * Sets the target for the target device (in the virtual machine). * * @param target target for the target device (in the virtual machine). */ - public void setTarget( T target ); + public void setPciTarget( T target ); } diff --git a/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java b/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java index d2be2d6..1351f26 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java +++ b/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java @@ -8,8 +8,7 @@ import org.openslx.libvirt.xml.LibvirtXmlNode; * @author Manuel Bentele * @version 1.0 */ -public class HostdevPci extends Hostdev implements HostdevAddressableSource<HostdevPciDeviceAddress>, - HostdevAddressableTarget<HostdevPciDeviceAddress> +public class HostdevPci extends Hostdev implements HostdevAddressableSource<HostdevPciDeviceAddress> { /** * Creates an empty hostdev PCI device. @@ -29,46 +28,6 @@ public class HostdevPci extends Hostdev implements HostdevAddressableSource<Host super( xmlNode ); } - /** - * Returns the PCI device address from an address XML element selected by a XPath expression. - * - * @param expression XPath expression to select the XML address element. - * @return PCI device address from the selected XML address element. - */ - private HostdevPciDeviceAddress getPciAddress( final String expression ) - { - String pciDomain = this.getXmlElementAttributeValue( expression, "domain" ); - String pciBus = this.getXmlElementAttributeValue( expression, "bus" ); - String pciDevice = this.getXmlElementAttributeValue( expression, "slot" ); - String pciFunction = this.getXmlElementAttributeValue( expression, "function" ); - - pciDomain = HostdevUtils.removeHexPrefix( pciDomain ); - pciBus = HostdevUtils.removeHexPrefix( pciBus ); - pciDevice = HostdevUtils.removeHexPrefix( pciDevice ); - pciFunction = HostdevUtils.removeHexPrefix( pciFunction ); - - return HostdevPciDeviceAddress.valueOf( pciDomain + ":" + pciBus + ":" + pciDevice + "." + pciFunction ); - } - - /** - * Sets the PCI device address for an XML address element selected by a XPath expression. - * - * @param expression XPath expression to select the XML address element. - * @param address PCI device address for the selected XML address element. - */ - private void setPciAddress( final String expression, final HostdevPciDeviceAddress address ) - { - final String pciDomain = HostdevUtils.appendHexPrefix( address.getPciDomainAsString() ); - final String pciBus = HostdevUtils.appendHexPrefix( address.getPciBusAsString() ); - final String pciDevice = HostdevUtils.appendHexPrefix( address.getPciDeviceAsString() ); - final String pciFunction = HostdevUtils.appendHexPrefix( address.getPciFunctionAsString() ); - - this.setXmlElementAttributeValue( expression, "domain", pciDomain ); - this.setXmlElementAttributeValue( expression, "bus", pciBus ); - this.setXmlElementAttributeValue( expression, "slot", pciDevice ); - this.setXmlElementAttributeValue( expression, "function", pciFunction ); - } - @Override public HostdevPciDeviceAddress getSource() { @@ -81,16 +40,14 @@ public class HostdevPci extends Hostdev implements HostdevAddressableSource<Host this.setPciAddress( "source/address", address ); } - @Override - public HostdevPciDeviceAddress getTarget() - { - return this.getPciAddress( "address" ); - } - - @Override - public void setTarget( HostdevPciDeviceAddress address ) + /** + * Set multifunction mode. + * + * If enabled, the device is said to have multiple functions. + */ + public void setMultifunction( boolean on ) { - this.setPciAddress( "address", address ); + this.setXmlElementAttributeValueOnOff( "address", "multifunction", on ); } /** diff --git a/src/main/java/org/openslx/libvirt/domain/device/HostdevUsb.java b/src/main/java/org/openslx/libvirt/domain/device/HostdevUsb.java index a9d7f89..b5332af 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/HostdevUsb.java +++ b/src/main/java/org/openslx/libvirt/domain/device/HostdevUsb.java @@ -52,7 +52,7 @@ public class HostdevUsb extends Hostdev implements HostdevAddressableSource<Host } @Override - public HostdevUsbDeviceAddress getTarget() + public HostdevUsbDeviceAddress getPciTarget() { final String usbBus = this.getXmlElementAttributeValue( "address", "bus" ); final String usbPort = this.getXmlElementAttributeValue( "address", "port" ); @@ -61,7 +61,7 @@ public class HostdevUsb extends Hostdev implements HostdevAddressableSource<Host } @Override - public void setTarget( HostdevUsbDeviceAddress address ) + public void setPciTarget( HostdevUsbDeviceAddress address ) { this.setXmlElementAttributeValue( "address", "bus", Integer.toString( address.getUsbBus() ) ); this.setXmlElementAttributeValue( "address", "port", Integer.toString( address.getUsbPort() ) ); |