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;
}
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);
}
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);
}
}
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);
}
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();
}
Aggregations