use of org.ovirt.engine.core.common.businessentities.storage.DiskInterface 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.common.businessentities.storage.DiskInterface in project ovirt-engine by oVirt.
the class LibvirtVmXmlBuilder method writeDisks.
private void writeDisks(List<VmDevice> devices) {
Map<VmDeviceId, VmDevice> deviceIdToDevice = devices.stream().collect(Collectors.toMap(VmDevice::getId, dev -> dev));
Map<Integer, Map<VmDevice, Integer>> vmDeviceSpaprVscsiUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForSpaprScsiDisks(vm);
Map<Integer, Map<VmDevice, Integer>> vmDeviceVirtioScsiUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForVirtioScsiDisks(vm);
int hdIndex = -1;
int sdIndex = -1;
int vdIndex = -1;
int pinnedDriveIndex = 0;
Map<Disk, VmDevice> vmDisksToDevices = vm.getDiskMap().values().stream().map(d -> new Pair<>(d, deviceIdToDevice.get(new VmDeviceId(d.getId(), vm.getId())))).filter(p -> p.getSecond() != null && p.getSecond().isManaged()).collect(Collectors.toMap(Pair::getFirst, Pair::getSecond));
for (Entry<Disk, VmDevice> diskAndDevice : vmInfoBuildUtils.getSortedDisks(vmDisksToDevices, vm.getId())) {
Disk disk = diskAndDevice.getKey();
VmDevice device = diskAndDevice.getValue();
DiskVmElement dve = disk.getDiskVmElementForVm(vm.getId());
DiskInterface diskInterface = dve.getDiskInterface();
int index = 0;
int pinTo = 0;
switch(diskInterface) {
case IDE:
index = hdIndex = skipCdIndices(++hdIndex, diskInterface);
break;
case VirtIO:
pinTo = vmInfoBuildUtils.pinToIoThreads(vm, pinnedDriveIndex++);
index = vdIndex = skipCdIndices(++vdIndex, diskInterface);
break;
case SPAPR_VSCSI:
case VirtIO_SCSI:
vmInfoBuildUtils.calculateAddressForScsiDisk(vm, disk, device, vmDeviceSpaprVscsiUnitMap, vmDeviceVirtioScsiUnitMap);
case SATA:
index = sdIndex = skipCdIndices(++sdIndex, diskInterface);
break;
}
String dev = vmInfoBuildUtils.makeDiskName(dve.getDiskInterface().getName(), index);
writeDisk(device, disk, dve, dev, pinTo);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskInterface 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;
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskInterface in project ovirt-engine by oVirt.
the class AbstractDiskModel method flush.
public void flush() {
switch(getDiskStorageType().getEntity()) {
case LUN:
LunDisk lunDisk = getLunDisk();
DiskInterface diskInterface = getDiskInterface().getSelectedItem();
if (DiskInterface.VirtIO_SCSI.equals(diskInterface)) {
lunDisk.setSgio(!getIsScsiPassthrough().getEntity() ? null : getIsSgIoUnfiltered().getEntity() ? ScsiGenericIO.UNFILTERED : ScsiGenericIO.FILTERED);
if (!getIsFloating()) {
getDiskVmElement().setUsingScsiReservation(getIsUsingScsiReservation().getEntity());
}
} else {
getIsScsiPassthrough().setEntity(false);
lunDisk.setSgio(null);
if (!getIsFloating()) {
getDiskVmElement().setUsingScsiReservation(false);
}
}
setDisk(lunDisk);
break;
case CINDER:
CinderDisk cinderDisk = getCinderDisk();
updateQuota(cinderDisk);
updateDiskSize(cinderDisk);
setDisk(cinderDisk);
break;
case IMAGE:
DiskImage diskImage = getDiskImage();
// For a long time it was possible to delete all disk profiles
if (getDiskProfile().getSelectedItem() != null) {
diskImage.setDiskProfileId(getDiskProfile().getSelectedItem().getId());
}
updateQuota(diskImage);
updateDiskSize(diskImage);
setDisk(diskImage);
break;
}
getDisk().setDiskAlias(getAlias().getEntity());
getDisk().setDiskDescription(getDescription().getEntity());
getDisk().setWipeAfterDelete(getIsWipeAfterDelete().getEntity());
getDisk().setShareable(getIsShareable().getEntity());
getDisk().setPlugged(getIsPlugged().getEntity());
getDisk().setPropagateErrors(PropagateErrors.Off);
if (getVm() != null) {
getDiskVmElement().setReadOnly(getIsReadOnly().getIsAvailable() ? getIsReadOnly().getEntity() : false);
getDiskVmElement().setBoot(getIsBootable().getEntity());
getDiskVmElement().setDiskInterface(getDiskInterface().getSelectedItem());
getDiskVmElement().setPassDiscard(getPassDiscard().getEntity());
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskInterface in project ovirt-engine by oVirt.
the class AbstractDiskModel method updatePassDiscardAvailability.
protected void updatePassDiscardAvailability() {
if (!AsyncDataProvider.getInstance().isPassDiscardFeatureSupported(getDataCenter().getSelectedItem().getCompatibilityVersion())) {
getPassDiscard().setIsAvailable(false);
return;
}
if (getIsFloating()) {
getPassDiscard().setIsAvailable(false);
} else {
DiskInterface selectedInterface = getDiskInterface().getSelectedItem();
DiskStorageType selectedDiskStorageType = getDiskStorageType().getEntity();
boolean isApplicableInterface = selectedInterface == DiskInterface.VirtIO_SCSI || selectedInterface == DiskInterface.IDE;
boolean isApplicableDiskStorageType = selectedDiskStorageType == DiskStorageType.LUN || selectedDiskStorageType == DiskStorageType.IMAGE;
boolean isApplicableStorageType = selectedDiskStorageType == DiskStorageType.LUN || (getStorageDomain().getSelectedItem() != null && getStorageDomain().getSelectedItem().getStorageType().isInternal());
if (isApplicableInterface && isApplicableDiskStorageType && isApplicableStorageType) {
getPassDiscard().setIsAvailable(true);
if (!getIsNew()) {
getPassDiscard().setEntity(getDiskVmElement().isPassDiscard());
}
} else {
// Reset PassDiscard's availability and value.
getPassDiscard().setIsAvailable(false);
getPassDiscard().setEntity(false);
}
}
}
Aggregations