use of org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices in project ovirt-engine by oVirt.
the class VmInfoBuilderImpl method buildVmVirtioScsi.
@Override
public void buildVmVirtioScsi() {
List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSCSI);
Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
int virtioScsiIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
for (VmDevice vmDevice : vmDevices) {
Map<String, Object> struct = new HashMap<>();
struct.put(VdsProperties.Type, VmDeviceGeneralType.CONTROLLER.getValue());
struct.put(VdsProperties.Device, VdsProperties.Scsi);
struct.put(VdsProperties.Model, VdsProperties.VirtioScsi);
struct.put(VdsProperties.Index, Integer.toString(virtioScsiIndex));
vmInfoBuildUtils.addAddress(vmDevice, struct);
virtioScsiIndex++;
addDevice(struct, vmDevice, null);
}
}
use of org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices in project ovirt-engine by oVirt.
the class AbstractDiskVmCommand method getDiskAddressMap.
/**
* Returns disk's address map by specified VmDevice and DiskInterface
* (note: for VirtIO_SCSI/SPAPR_VSCSI interfaces, the method updates the VM device's address accordingly).
* @return disk's address map
*/
public Map<String, String> getDiskAddressMap(VmDevice vmDevice, DiskInterface diskInterface) {
String address = vmDevice.getAddress();
if (diskInterface != DiskInterface.VirtIO_SCSI && diskInterface != DiskInterface.SPAPR_VSCSI) {
if (StringUtils.isNotBlank(address)) {
return StringMapUtils.string2Map(address);
}
} else {
EngineLock vmDiskHotPlugEngineLock = null;
try {
vmDiskHotPlugEngineLock = lockVmDiskHotPlugWithWait();
VM vm = vmDao.get(getParameters().getVmId());
Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
int virtioScsiIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
int sPaprVscsiIndex = controllerIndexMap.get(DiskInterface.SPAPR_VSCSI);
if (diskInterface == DiskInterface.VirtIO_SCSI) {
Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForVirtioScsiDisks(getVm());
return getAddressMapForScsiDisk(address, vmDeviceUnitMapForController(vmDevice, vmDeviceUnitMap), vmDevice, virtioScsiIndex, false, false);
} else if (diskInterface == DiskInterface.SPAPR_VSCSI) {
Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForSpaprScsiDisks(getVm());
return getAddressMapForScsiDisk(address, vmDeviceUnitMapForController(vmDevice, vmDeviceUnitMap), vmDevice, sPaprVscsiIndex, true, true);
}
} finally {
lockManager.releaseLock(vmDiskHotPlugEngineLock);
}
}
return null;
}
use of org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices in project ovirt-engine by oVirt.
the class LibvirtVmXmlBuilder method writeDevices.
private void writeDevices() {
List<VmDevice> devices = vmInfoBuildUtils.getVmDevices(vm.getId());
// replacement of some devices in run-once mode should eventually be done by the run-command
devices = overrideDevicesForRunOnce(devices);
devices = processPayload(devices);
devices.stream().filter(d -> d.getSpecParams() == null).forEach(d -> d.setSpecParams(Collections.emptyMap()));
writer.writeStartElement("devices");
if (vm.getClusterArch() != ArchitectureType.s390x && !(vm.getClusterArch().getFamily() == ArchitectureType.ppc && vm.getVmType() == VmType.HighPerformance)) {
// no mouse or tablet for s390x and for HP VMS with ppc architecture type
writeInput();
}
writeGuestAgentChannels();
if (vm.getClusterArch() == ArchitectureType.ppc64 || vm.getClusterArch() == ArchitectureType.ppc64le) {
writeEmulator();
}
Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
int virtioScsiIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
List<VmDevice> interfaceDevices = new ArrayList<>();
List<VmDevice> diskDevices = new ArrayList<>();
List<VmDevice> cdromDevices = new ArrayList<>();
VmDevice floppyDevice = null;
boolean spiceExists = false;
boolean balloonExists = false;
boolean forceRefreshDevices = false;
for (VmDevice device : devices) {
if (!device.isPlugged()) {
continue;
}
switch(device.getType()) {
case BALLOON:
balloonExists = true;
writeBalloon(device);
break;
case SMARTCARD:
writeSmartcard(device);
break;
case WATCHDOG:
writeWatchdog(device);
break;
case MEMORY:
// memory devices are only used for hot-plug
break;
case VIDEO:
writeVideo(device);
break;
case CONTROLLER:
switch(device.getDevice()) {
case "virtio-serial":
device.getSpecParams().put("index", 0);
device.getSpecParams().put("ports", 16);
break;
case "virtio-scsi":
device.setDevice(VdsProperties.Scsi);
device.getSpecParams().put("index", virtioScsiIndex++);
device.getSpecParams().put("model", "virtio-scsi");
break;
}
writeController(device);
break;
case GRAPHICS:
writeGraphics(device);
spiceExists = spiceExists || device.getDevice().equals("spice");
break;
case SOUND:
writeSound(device);
break;
case RNG:
writeRng(device);
break;
case CONSOLE:
writeConsole(device);
if ("serial".equals(device.getSpecParams().get("consoleType"))) {
serialConsolePath = getSerialConsolePath(device);
}
break;
case DISK:
switch(VmDeviceType.getByName(device.getDevice())) {
case CDROM:
cdromDevices.add(device);
break;
case DISK:
diskDevices.add(device);
break;
case FLOPPY:
if (floppyDevice == null || !VmPayload.isPayload(floppyDevice.getSpecParams())) {
floppyDevice = device;
}
break;
default:
}
break;
case INTERFACE:
interfaceDevices.add(device);
break;
case REDIR:
writeRedir(device);
break;
case REDIRDEV:
break;
case CHANNEL:
break;
case HOSTDEV:
HostDevice hostDevice = hostDevicesSupplier.get().get(device.getDevice());
if (hostDevice == null) {
if (!"mdev".equals(device.getDevice())) {
log.info("skipping VM host device {} for VM {}, no corresponding host device was found", device.getDevice(), device.getVmId());
}
forceRefreshDevices = true;
break;
}
writeHostDevice(device, hostDevice);
break;
case UNKNOWN:
break;
default:
break;
}
}
if (forceRefreshDevices) {
vmInfoBuildUtils.refreshVmDevices(vm.getId());
}
if (!balloonExists) {
writeDefaultBalloon();
}
writeSerialConsole(serialConsolePath);
if (spiceExists) {
writeSpiceVmcChannel();
}
updateBootOrder(diskDevices, cdromDevices, interfaceDevices);
writeInterfaces(interfaceDevices);
writeCdRom(cdromDevices);
writeFloppy(floppyDevice);
// we must write the disk after writing cd-rom and floppy to know reserved indices
writeDisks(diskDevices);
writeLeases();
writer.writeEndElement();
}
use of org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method calculateAddressForScsiDisk.
public void calculateAddressForScsiDisk(VM vm, Disk disk, VmDevice device, Map<Integer, Map<VmDevice, Integer>> vmDeviceSpaprVscsiUnitMap, Map<Integer, Map<VmDevice, Integer>> vmDeviceVirtioScsiUnitMap) {
Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
int defaultSpaprVscsiControllerIndex = controllerIndexMap.get(DiskInterface.SPAPR_VSCSI);
int defaultVirtioScsiControllerIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
Integer unitIndex = null;
switch(disk.getDiskVmElementForVm(vm.getId()).getDiskInterface()) {
case SPAPR_VSCSI:
if (StringUtils.isEmpty(device.getAddress())) {
unitIndex = vmDeviceSpaprVscsiUnitMap.get(defaultSpaprVscsiControllerIndex).get(device);
device.setAddress(createAddressForScsiDisk(defaultSpaprVscsiControllerIndex, unitIndex).toString());
}
break;
case VirtIO_SCSI:
int controllerIndex = defaultVirtioScsiControllerIndex;
VmDevice deviceFromMap = device;
for (Map.Entry<Integer, Map<VmDevice, Integer>> controllerToDevices : vmDeviceVirtioScsiUnitMap.entrySet()) {
Optional<VmDevice> maybeDeviceFromMap = controllerToDevices.getValue().keySet().stream().filter(d -> d.getId().equals(device.getId())).findFirst();
if (maybeDeviceFromMap.isPresent()) {
deviceFromMap = maybeDeviceFromMap.get();
controllerIndex = controllerToDevices.getKey();
unitIndex = controllerToDevices.getValue().get(deviceFromMap);
break;
}
}
if (StringUtils.isEmpty(deviceFromMap.getAddress())) {
if (unitIndex == null) {
// should never get here, but for safety having this fallback and generating a new unit id
unitIndex = getAvailableUnitForScsiDisk(vmDeviceVirtioScsiUnitMap.get(controllerIndex), false, false);
log.debug("The unit was null for disk '{}' on controller '{}', generating a new one '{}'", disk.getId(), controllerIndex, unitIndex);
}
device.setAddress(createAddressForScsiDisk(controllerIndex, unitIndex).toString());
}
break;
}
}
Aggregations