Search in sources :

Example 41 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class VfSchedulerImpl method getFreeVf.

private HostDevice getFreeVf(Guid nicId, Map<Guid, List<String>> nicToUsedVfs, Map<Guid, VdsNetworkInterface> fetchedNics, List<String> skipVfs) {
    VdsNetworkInterface nic = getNic(nicId, fetchedNics);
    List<String> usedVfsByNic = nicToUsedVfs.get(nic.getId());
    if (usedVfsByNic != null) {
        skipVfs.addAll(usedVfsByNic);
    }
    HostDevice freeVf = networkDeviceHelper.getFreeVf(nic, skipVfs);
    if (freeVf != null) {
        if (usedVfsByNic == null) {
            usedVfsByNic = new ArrayList<>();
            nicToUsedVfs.put(nic.getId(), usedVfsByNic);
        }
        usedVfsByNic.add(freeVf.getName());
        return freeVf;
    }
    return null;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 42 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class RefreshHostDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    VDSReturnValue vdsReturnValue = resourceManager.runVdsCommand(VDSCommandType.HostDevListByCaps, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
    if (!vdsReturnValue.getSucceeded()) {
        return;
    }
    List<HostDevice> fetchedDevices = (List<HostDevice>) vdsReturnValue.getReturnValue();
    List<HostDevice> oldDevices = hostDeviceDao.getHostDevicesByHostId(getVdsId());
    Map<String, HostDevice> oldMap = Entities.entitiesByName(oldDevices);
    fetchedMap = filterOrphanedDevices(Entities.entitiesByName(fetchedDevices));
    final List<HostDevice> newDevices = new ArrayList<>();
    final List<HostDevice> changedDevices = new ArrayList<>();
    for (Map.Entry<String, HostDevice> entry : fetchedMap.entrySet()) {
        HostDevice device = entry.getValue();
        if (oldMap.containsKey(entry.getKey())) {
            if (!oldMap.get(entry.getKey()).equals(device)) {
                changedDevices.add(device);
            }
        } else {
            newDevices.add(device);
        }
    }
    final List<HostDevice> removedDevices = new ArrayList<>();
    final List<VmDevice> removedVmDevices = new ArrayList<>();
    for (Map.Entry<String, HostDevice> entry : oldMap.entrySet()) {
        final String deviceName = entry.getKey();
        if (!fetchedMap.containsKey(deviceName)) {
            removedDevices.add(entry.getValue());
            if (getAttachedVmDevicesMap().containsKey(deviceName)) {
                List<VmDevice> vmDevices = getAttachedVmDevicesMap().get(deviceName);
                for (VmDevice vmDevice : vmDevices) {
                    log.warn("Removing VM[{}]'s hostDevice[{}] because it no longer exists on host {}", vmDevice.getVmId(), deviceName, getVds());
                    removedVmDevices.add(vmDevice);
                }
            }
        }
    }
    try {
        hostLocking.acquireHostDevicesLock(getVdsId());
        TransactionSupport.executeInNewTransaction(() -> {
            hostDeviceDao.saveAllInBatch(newDevices);
            hostDeviceDao.updateAllInBatch(changedDevices);
            hostDeviceDao.removeAllInBatch(removedDevices);
            handleHostNicVfsConfigUpdate();
            vmDeviceDao.removeAllInBatch(removedVmDevices);
            return null;
        });
    } finally {
        hostLocking.releaseHostDevicesLock(getVdsId());
    }
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 43 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class RefreshHostDevicesCommand method removeInvalidHostNicVfsConfigsFromDb.

private void removeInvalidHostNicVfsConfigsFromDb() {
    final List<HostNicVfsConfig> hostNicVfsConfigsToRemove = new ArrayList<>();
    List<HostNicVfsConfig> hostNicVfsConfigs = hostNicVfsConfigDao.getAllVfsConfigByHostId(getVdsId());
    for (HostNicVfsConfig hostNicVfsConfig : hostNicVfsConfigs) {
        VdsNetworkInterface nic = interfaceDao.get(hostNicVfsConfig.getNicId());
        HostDevice pciDevice = null;
        if (nic != null) {
            String pciDeviceName = networkDeviceHelper.getPciDeviceNameByNic(nic);
            pciDevice = fetchedMap.get(pciDeviceName);
        }
        if (nic == null || pciDevice == null || !networkDeviceHelper.isSriovDevice(pciDevice)) {
            addToListIfNotNull(hostNicVfsConfig, hostNicVfsConfigsToRemove);
        }
    }
    if (!hostNicVfsConfigsToRemove.isEmpty()) {
        hostNicVfsConfigDao.removeAllInBatch(hostNicVfsConfigsToRemove);
    }
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 44 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class RemoveVmHostDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    Set<HostDevice> affectedHostDevices = getAffectedHostDevices();
    Map<String, VmHostDevice> existingDevices = getExistingVmHostDevicesByName();
    Map<Integer, List<VmHostDevice>> existingDevicesByIommuGroup = new HashMap<>();
    for (HostDevice hostDevice : affectedHostDevices) {
        boolean shouldRemoveDevice = getPrimaryDeviceNames().contains(hostDevice.getDeviceName());
        boolean deviceExists = existingDevices.containsKey(hostDevice.getDeviceName());
        if (deviceExists) {
            VmHostDevice device = existingDevices.get(hostDevice.getDeviceName());
            existingDevicesByIommuGroup.computeIfAbsent(getIommuGroupKey(hostDevice.getIommuGroup()), k -> new ArrayList<>()).add(device);
            if (shouldRemoveDevice) {
                // first just set the flag that this device is not required
                device.setIommuPlaceholder(true);
            }
        }
    }
    List<VmDevice> devicesToRemove = new ArrayList<>();
    List<VmDevice> devicesToUpdate = new ArrayList<>();
    // no longer needed (placeholder) devices
    for (Map.Entry<Integer, List<VmHostDevice>> group : existingDevicesByIommuGroup.entrySet()) {
        List<VmHostDevice> devices = group.getValue();
        // devices without IOMMU group can be safely removed
        boolean noIommuDeviceGroup = group.getKey() == getIommuGroupKey(null);
        if (noIommuDeviceGroup || allPlaceholder(devices)) {
            // all devices in this group became unnecessary, so remove them
            devicesToRemove.addAll(devices);
        } else {
            // some devices in this group are still required so just update the placeholder flag
            devicesToUpdate.addAll(devices);
        }
    }
    vmDeviceDao.removeAllInBatch(devicesToRemove);
    vmDeviceDao.updateAllInBatch(devicesToUpdate);
    setSucceeded(true);
}
Also used : VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmHostDevicesParameters(org.ovirt.engine.core.common.action.VmHostDevicesParameters) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice)

Example 45 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class VmDevicesConverter method getHostDeviceName.

private String getHostDeviceName(XmlNode hostDevInterfaceNode, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
    Map<String, String> hostAddress = parseHostAddress(hostDevInterfaceNode);
    if (hostAddress == null) {
        return null;
    }
    HostDevice hostDevice = addressToHostDeviceSupplier.get().get(hostAddress);
    if (hostDevice == null) {
        return null;
    }
    return hostDevice.getDeviceName();
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice)

Aggregations

HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)46 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)16 Guid (org.ovirt.engine.core.compat.Guid)14 Map (java.util.Map)11 List (java.util.List)10 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)10 HashMap (java.util.HashMap)9 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)9 Collectors (java.util.stream.Collectors)8 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)7 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)7 HostDeviceDao (org.ovirt.engine.core.dao.HostDeviceDao)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Objects (java.util.Objects)6 Inject (javax.inject.Inject)6 StringUtils (org.apache.commons.lang.StringUtils)6 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)6 VmDeviceDao (org.ovirt.engine.core.dao.VmDeviceDao)6