Martin Betak has uploaded a new change for review. Change subject: backend: Add HostDev passthrough support ......................................................................
backend: Add HostDev passthrough support Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1099760 Change-Id: Ia5575c0db797d7d04339c4b309bb4325e853ffed Signed-off-by: Martin Betak <mbe...@redhat.com> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDevice.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDeviceId.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java A backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/HostDevListByCapsVDSCommand.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java A backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostDevListReturnForXmlRpc.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java A packaging/dbscripts/upgrade/03_06_0590_add_host_device_table.sql 13 files changed, 341 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/35892/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDevice.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDevice.java new file mode 100644 index 0000000..901527c --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDevice.java @@ -0,0 +1,110 @@ +package org.ovirt.engine.core.common.businessentities; + +import org.ovirt.engine.core.compat.Guid; + +import java.io.Serializable; + +public class HostDevice implements BusinessEntity<HostDeviceId> { + + private Guid hostId; + private String deviceName; + private Guid vmId; + private String parentDeviceName; + private String capability; + private int iommuGroup; + private String productName; + private String productId; + private String vendorName; + private String vendorId; + + public Guid getHostId() { + return hostId; + } + + public void setHostId(Guid hostId) { + this.hostId = hostId; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public void setVmId(Guid vmId) { + this.vmId = vmId; + } + + public Guid getVmId() { + return vmId; + } + + public void setCapability(String capability) { + this.capability = capability; + } + + public String getCapability() { + return capability; + } + + public void setIommuGroup(int iommuGroup) { + this.iommuGroup = iommuGroup; + } + + public int getIommuGroup() { + return iommuGroup; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public String getProductName() { + return productName; + } + + public void setProductId(String productId) { + this.productId = productId; + } + + public String getProductId() { + return productId; + } + + public void setVendorName(String vendorName) { + this.vendorName = vendorName; + } + + public String getVendorName() { + return vendorName; + } + + public void setVendorId(String vendorId) { + this.vendorId = vendorId; + } + + public String getVendorId() { + return vendorId; + } + + public void setParentDeviceName(String parentDeviceName) { + this.parentDeviceName = parentDeviceName; + } + + public String getParentDeviceName() { + return parentDeviceName; + } + + @Override + public HostDeviceId getId() { + return new HostDeviceId(hostId, deviceName); + } + + @Override + public void setId(HostDeviceId id) { + setHostId(id.getHostId()); + setDeviceName(id.getDeviceName()); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDeviceId.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDeviceId.java new file mode 100644 index 0000000..cf2133e --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/HostDeviceId.java @@ -0,0 +1,63 @@ +package org.ovirt.engine.core.common.businessentities; + +import org.ovirt.engine.core.common.utils.ObjectUtils; +import org.ovirt.engine.core.compat.Guid; + +import java.io.Serializable; + +public final class HostDeviceId implements Serializable { + + private Guid hostId; + private String deviceName; + + public HostDeviceId() { + } + + public HostDeviceId(Guid hostId, String deviceName) { + this.hostId = hostId; + this.deviceName = deviceName; + } + + public Guid getHostId() { + return hostId; + } + + public void setHostId(Guid hostId) { + this.hostId = hostId; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + HostDeviceId other = (HostDeviceId) o; + return ObjectUtils.objectsEqual(hostId, other.hostId) && + ObjectUtils.objectsEqual(deviceName, other.deviceName); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((hostId == null) ? 0 : hostId.hashCode()); + result = prime * result + ((deviceName == null) ? 0 : deviceName.hashCode()); + return result; + } + + @Override + public String toString() { + return String.format("hostId = %s, deviceName = %s", getHostId(), getDeviceName()); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java index 2c41867..86e46e3 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java @@ -166,6 +166,7 @@ List("org.ovirt.engine.core.vdsbroker.vdsbroker"), // get a list of VMs with status only GetVmStats("org.ovirt.engine.core.vdsbroker.vdsbroker"), // get a VM with full data and statistics GetAllVmStats("org.ovirt.engine.core.vdsbroker.vdsbroker"), // get a list of VMs with full data and statistics + HostDevListByCaps("org.ovirt.engine.core.vdsbroker"), // get all host devices with passthrough information Destroy("org.ovirt.engine.core.vdsbroker.vdsbroker"), // Clean a DOWN VM from the vms list /** * Get Host capabilities diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java new file mode 100644 index 0000000..1fee6ec --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java @@ -0,0 +1,11 @@ +package org.ovirt.engine.core.dao; + +import org.ovirt.engine.core.common.businessentities.HostDevice; +import org.ovirt.engine.core.compat.Guid; + +import java.util.List; + +public interface HostDeviceDao extends GenericDao { + List<HostDevice> getHostDevicesByHostIdAndDeviceName(Guid hostId, String deviceName); + List<HostDevice> getHostDevicesByHostId(Guid hostId); +} diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/HostDevListByCapsVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/HostDevListByCapsVDSCommand.java new file mode 100644 index 0000000..d5ca3f3 --- /dev/null +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/HostDevListByCapsVDSCommand.java @@ -0,0 +1,42 @@ +package org.ovirt.engine.core.vdsbroker; + +import org.ovirt.engine.core.common.businessentities.HostDevice; +import org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase; +import org.ovirt.engine.core.vdsbroker.vdsbroker.HostDevListReturnForXmlRpc; +import org.ovirt.engine.core.vdsbroker.vdsbroker.StatusForXmlRpc; +import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsBrokerCommand; +import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsBrokerObjectsBuilder; + +import java.util.List; + +public class HostDevListByCapsVDSCommand<P extends VdsIdAndVdsVDSCommandParametersBase> extends VdsBrokerCommand<P> { + + private HostDevListReturnForXmlRpc hostDevListReturnForXmlRpc; + + public HostDevListByCapsVDSCommand(P parameters) { + super(parameters); + } + + @Override + protected void executeVdsBrokerCommand() { + hostDevListReturnForXmlRpc = getBroker().hostDevListByCaps(); + proceedProxyReturnValue(); + List<HostDevice> devices = VdsBrokerObjectsBuilder.buildHostDevices(hostDevListReturnForXmlRpc.devices); + setReturnValue(devices); + } + + @Override + protected StatusForXmlRpc getReturnStatus() { + return hostDevListReturnForXmlRpc.status; + } + + @Override + protected Object getReturnValueFromBroker() { + return hostDevListReturnForXmlRpc; + } + + @Override + protected boolean getIsPrintReturnValue() { + return false; + } +} diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java index 9e970e4..5b5ef55 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java @@ -31,6 +31,7 @@ import org.ovirt.engine.core.vdsbroker.vdsbroker.AlignmentScanReturnForXmlRpc; import org.ovirt.engine.core.vdsbroker.vdsbroker.DevicesVisibilityMapReturnForXmlRpc; import org.ovirt.engine.core.vdsbroker.vdsbroker.FenceStatusReturnForXmlRpc; +import org.ovirt.engine.core.vdsbroker.vdsbroker.HostDevListReturnForXmlRpc; import org.ovirt.engine.core.vdsbroker.vdsbroker.IQNListReturnForXmlRpc; import org.ovirt.engine.core.vdsbroker.vdsbroker.IVdsServer; import org.ovirt.engine.core.vdsbroker.vdsbroker.ImageSizeReturnForXmlRpc; @@ -256,6 +257,14 @@ } @Override + public HostDevListReturnForXmlRpc hostDevListByCaps() { + JsonRpcRequest request = new RequestBuilder("Host.hostdevListByCaps").build(); + Map<String, Object> response = + new FutureMap(this.client, request).withResponseKey("deviceList"); + return new HostDevListReturnForXmlRpc(response); + } + + @Override public StatusOnlyReturnForXmlRpc migrate(Map<String, String> migrationInfo) { JsonRpcRequest request = new RequestBuilder("VM.migrate").withParameter("vmID", getVmId(migrationInfo)) diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostDevListReturnForXmlRpc.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostDevListReturnForXmlRpc.java new file mode 100644 index 0000000..7e68f37 --- /dev/null +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostDevListReturnForXmlRpc.java @@ -0,0 +1,15 @@ +package org.ovirt.engine.core.vdsbroker.vdsbroker; + +import java.util.Map; + +@SuppressWarnings("unchecked") +public class HostDevListReturnForXmlRpc { + + public final StatusForXmlRpc status; + public final Map<String, Map<String, Object>> devices; + + public HostDevListReturnForXmlRpc(Map<String, Object> innerMap) { + status = new StatusForXmlRpc((Map<String, Object>) innerMap.get(VdsProperties.status)); + devices = (Map<String, Map<String, Object>>) innerMap.get(VdsProperties.DEVICE_LIST); + } +} diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java index 92619fa..c67b9b0 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java @@ -66,6 +66,8 @@ VMInfoListReturnForXmlRpc getAllVmStats(); + HostDevListReturnForXmlRpc hostDevListByCaps(); + StatusOnlyReturnForXmlRpc migrate(Map<String, String> migrationInfo); StatusOnlyReturnForXmlRpc migrateStatus(String vmId); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java index 61420d2..cf332a9 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java @@ -25,6 +25,7 @@ import org.ovirt.engine.core.common.businessentities.DiskImageDynamic; import org.ovirt.engine.core.common.businessentities.DisplayType; import org.ovirt.engine.core.common.businessentities.Entities; +import org.ovirt.engine.core.common.businessentities.HostDevice; import org.ovirt.engine.core.common.businessentities.KdumpStatus; import org.ovirt.engine.core.common.businessentities.LUNs; import org.ovirt.engine.core.common.businessentities.NumaNodeStatistics; @@ -1745,4 +1746,48 @@ } return list; } + + /** + * Parse Host Device Information + * + * pci_0000_00_1d_2 = {'params': {'capability': 'pci', + 'iommu_group': '9', + 'parent': 'computer', + 'product': '82801JI (ICH10 Family) USB UHCI Controller #3', + 'product_id': '0x3a36', + 'vendor': 'Intel Corporation', + 'vendor_id': '0x8086'}} + + * @param deviceList + * @return + */ + public static List<HostDevice> buildHostDevices(Map<String, Map<String, Object>> deviceList) { + List<HostDevice> devices = new ArrayList<>(); + + for (Entry<String, Map<String, Object>> entry : deviceList.entrySet()) { + + Map<String, Object> params = (Map<String, Object>) entry.getValue().get(VdsProperties.PARAMS); + + HostDevice device = new HostDevice(); + device.setDeviceName(entry.getKey()); + device.setCapability(params.get(VdsProperties.CAPABILITY).toString()); + device.setIommuGroup(Integer.parseInt(params.get(VdsProperties.IOMMU_GROUP).toString())); + device.setProductName(params.get(VdsProperties.PRODUCT_NAME).toString()); + device.setProductId(params.get(VdsProperties.PRODUCT_ID).toString()); + device.setVendorName(params.get(VdsProperties.VENDOR_NAME).toString()); + device.setVendorId(params.get(VdsProperties.VENDOR_ID).toString()); + + if (params.containsKey(VdsProperties.PARENT_NAME)) { + device.setParentDeviceName(params.get(VdsProperties.PARENT_NAME).toString()); + } + + // if the device is attached to running VM, the `vmId` property will be set + if (entry.getValue().containsKey(VdsProperties.VM_ID)) { + device.setVmId(new Guid(entry.getValue().get(VdsProperties.VM_ID).toString())); + } + + } + + return devices; + } } diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java index 3047465..9a322e6 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java @@ -385,6 +385,19 @@ public static final String QOS_PEAK = "peak"; public static final String QOS_BURST = "burst"; + // host devices + public static final String ROOT_DEVICE = "computer"; + public static final String DEVICE_LIST = "deviceList"; + public static final String PARAMS = "params"; + public static final String CAPABILITY = "capability"; + public static final String IOMMU_GROUP = "iommu_group"; + public static final String PRODUCT_NAME = "product"; + public static final String PRODUCT_ID = "product_id"; + public static final String VENDOR_NAME = "vendor"; + public static final String VENDOR_ID = "vendor_id"; + public static final String VM_ID = "vmId"; + public static final String PARENT_NAME = "parent"; + // fencing policy parameters public static final String STORAGE_DOMAIN_HOST_ID_MAP = "storageDomainHostIdMap"; diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java index e97444b..0b459eb 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java @@ -40,6 +40,8 @@ public Map<String, Object> getAllVmStats(); + public Map<String, Object> hostdevListByCaps(); + public Map<String, Object> migrate(Map<String, String> migrationInfo); public Map<String, Object> migrateStatus(String vmId); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java index d027b50..7e03119 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java @@ -233,6 +233,16 @@ } @Override + public HostDevListReturnForXmlRpc hostDevListByCaps() { + try { + Map<String, Object> xmlRpcReturnValue = vdsServer.hostdevListByCaps(); + return new HostDevListReturnForXmlRpc(xmlRpcReturnValue); + } catch (UndeclaredThrowableException ute) { + throw new XmlRpcRunTimeException(ute); + } + } + + @Override public StatusOnlyReturnForXmlRpc migrate(Map<String, String> migrationInfo) { try { Map<String, Object> xmlRpcReturnValue = vdsServer.migrate(migrationInfo); diff --git a/packaging/dbscripts/upgrade/03_06_0590_add_host_device_table.sql b/packaging/dbscripts/upgrade/03_06_0590_add_host_device_table.sql new file mode 100644 index 0000000..11863a9 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_06_0590_add_host_device_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE host_device ( + host_id UUID NOT NULL, + vm_id UUID NOT NULL, + device_name VARCHAR(255) NOT NULL, + parent_device_name VARCHAR(255) NOT NULL, + capability VARCHAR(32) NOT NULL, + iommu_group INTEGER NOT NULL, + product_name VARCHAR(255), + product_id VARCHAR(255), + vendor_name VARCHAR(255), + vendor_id VARCHAR(255) +); + +ALTER TABLE ONLY host_device + ADD CONSTRAINT host_device_pk PRIMARY KEY (host_id, device_name); + +ALTER TABLE ONLY host_device + ADD CONSTRAINT fk_host_device_parent_name FOREIGN KEY (host_id, parent_device_name) REFERENCES host_device(host_id, device_name); \ No newline at end of file -- To view, visit http://gerrit.ovirt.org/35892 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia5575c0db797d7d04339c4b309bb4325e853ffed Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Betak <mbe...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches