use of org.ovirt.engine.core.common.businessentities.VmHostDevice in project ovirt-engine by oVirt.
the class AddVmHostDevicesCommand method executeCommand.
@Override
protected void executeCommand() {
Set<HostDevice> affectedHostDevices = getAffectedHostDevices();
Map<String, VmHostDevice> existingDevices = getExistingVmHostDevicesByName();
List<VmDevice> devicesToAdd = new ArrayList<>();
List<VmDevice> devicesToUpdate = new ArrayList<>();
for (HostDevice hostDevice : affectedHostDevices) {
if (!existingDevices.containsKey(hostDevice.getDeviceName())) {
VmHostDevice device = new VmHostDevice(getVmId(), hostDevice);
// if the device was not explicitly intended by the user (only added due to the IOMMU group
// we mark it as as placeholder
boolean required = getPrimaryDeviceNames().contains(device.getDevice());
device.setIommuPlaceholder(!required);
devicesToAdd.add(device);
} else {
VmHostDevice device = new VmHostDevice(existingDevices.get(hostDevice.getDeviceName()));
// as it is now explicitly requested by the user
if (getPrimaryDeviceNames().contains(device.getDevice()) && device.isIommuPlaceholder()) {
device.setIommuPlaceholder(false);
devicesToUpdate.add(device);
}
}
}
vmDeviceDao.saveAllInBatch(devicesToAdd);
vmDeviceDao.updateAllInBatch(devicesToUpdate);
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.VmHostDevice in project ovirt-engine by oVirt.
the class GetVmHostDevicesQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
Guid vmId = getParameters().getId();
setReturnValue(vmDeviceDao.getVmDeviceByVmIdAndType(vmId, VmDeviceGeneralType.HOSTDEV).stream().map(VmHostDevice::new).collect(Collectors.toList()));
}
use of org.ovirt.engine.core.common.businessentities.VmHostDevice 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);
}
Aggregations