Search in sources :

Example 41 with DiskVmElement

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

the class GetAllDisksByVmIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    List<Disk> allDisks = diskDao.getAllForVm(getParameters().getId(), getUserID(), getParameters().isFiltered());
    List<Disk> disks = new ArrayList<>();
    for (Disk disk : allDisks) {
        if (disk.getDiskStorageType() == DiskStorageType.IMAGE || disk.getDiskStorageType() == DiskStorageType.CINDER) {
            DiskImage diskImage = (DiskImage) disk;
            diskImage.getSnapshots().addAll(diskImageDao.getAllSnapshotsForLeaf(diskImage.getImageId()));
        }
        DiskVmElement dve = getDiskVmElement(disk);
        if (dve != null) {
            disk.setDiskVmElements(Collections.singletonList(dve));
            disks.add(disk);
        }
    }
    getQueryReturnValue().setReturnValue(disks);
}
Also used : ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 42 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement 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);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LoggerFactory(org.slf4j.LoggerFactory) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmCpuCountHelper(org.ovirt.engine.core.common.utils.VmCpuCountHelper) XmlTextWriter(org.ovirt.engine.core.utils.ovf.xml.XmlTextWriter) HugePageUtils(org.ovirt.engine.core.common.utils.HugePageUtils) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StringMapUtils(org.ovirt.engine.core.utils.StringMapUtils) VmDeviceCommonUtils.updateVmDevicesBootOrder(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.updateVmDevicesBootOrder) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics) Version(org.ovirt.engine.core.compat.Version) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Stream(java.util.stream.Stream) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) NumaSettingFactory(org.ovirt.engine.core.vdsbroker.vdsbroker.NumaSettingFactory) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) HashSet(java.util.HashSet) ArchStrategyFactory(org.ovirt.engine.core.utils.archstrategy.ArchStrategyFactory) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) HugePage(org.ovirt.engine.core.common.businessentities.HugePage) Network(org.ovirt.engine.core.common.businessentities.network.Network) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) Pair(org.ovirt.engine.core.common.utils.Pair) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VM(org.ovirt.engine.core.common.businessentities.VM) NumaTuneMode(org.ovirt.engine.core.common.businessentities.NumaTuneMode) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices) IoTuneUtils.ioTuneListFrom(org.ovirt.engine.core.vdsbroker.vdsbroker.IoTuneUtils.ioTuneListFrom) Comparator(java.util.Comparator) Collections(java.util.Collections) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Map(java.util.Map) HashMap(java.util.HashMap) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 43 with DiskVmElement

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

the class MoveDiskCommand method executeCommand.

@Override
protected void executeCommand() {
    List<DiskVmElement> diskVmElements = diskVmElementDao.getAllDiskVmElementsByDiskId(getParameters().getImageGroupID());
    ActionType actionType = getMoveActionType(diskVmElements);
    if (actionType == ActionType.MoveOrCopyDisk) {
        MoveDiskParameters moveDiskParameters = getParameters();
        // This is required to make MoveDiskCommand and MoveOrCopyDiskCommand have
        // different a commandId. Having the same commandId will make CommandsCache
        // return the wrong command and lead to unexpected results
        moveDiskParameters.setCommandId(null);
        setReturnValue(runInternalAction(actionType, moveDiskParameters, ExecutionHandler.createInternalJobContext(getContext(), getLock())));
    } else {
        Guid vmId = diskVmElements.get(0).getVmId();
        engineLock = lockVmWithWait(vmId);
        setReturnValue(runInternalAction(actionType, createLiveMigrateDiskParameters(getParameters(), vmId), ExecutionHandler.createInternalJobContext(getContext(), engineLock)));
    }
    setSucceeded(true);
}
Also used : MoveDiskParameters(org.ovirt.engine.core.common.action.MoveDiskParameters) ActionType(org.ovirt.engine.core.common.action.ActionType) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid)

Example 44 with DiskVmElement

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

the class UpdateVmDiskCommand method performDiskUpdate.

protected void performDiskUpdate(final boolean unlockImage) {
    if (shouldPerformMetadataUpdate()) {
        updateMetaDataDescription((DiskImage) getNewDisk());
    }
    final Disk diskForUpdate = diskDao.get(getParameters().getDiskInfo().getId());
    final DiskVmElement diskVmElementForUpdate = diskVmElementDao.get(new VmDeviceId(getOldDisk().getId(), getVmId()));
    applyUserChanges(diskForUpdate, diskVmElementForUpdate);
    TransactionSupport.executeInNewTransaction(new TransactionMethod<Object>() {

        @Override
        public Object runInTransaction() {
            vmStaticDao.incrementDbGeneration(getVm().getId());
            updateDeviceProperties();
            baseDiskDao.update(diskForUpdate);
            diskVmElementDao.update(diskVmElementForUpdate);
            switch(diskForUpdate.getDiskStorageType()) {
                case IMAGE:
                    DiskImage diskImage = (DiskImage) diskForUpdate;
                    diskImage.setQuotaId(getQuotaId());
                    if (unlockImage && diskImage.getImageStatus() == ImageStatus.LOCKED) {
                        diskImage.setImageStatus(ImageStatus.OK);
                    }
                    imageDao.update(diskImage.getImage());
                    updateQuota(diskImage);
                    updateDiskProfile();
                    break;
                case CINDER:
                    CinderDisk cinderDisk = (CinderDisk) diskForUpdate;
                    cinderDisk.setQuotaId(getQuotaId());
                    setStorageDomainId(cinderDisk.getStorageIds().get(0));
                    getCinderBroker().updateDisk(cinderDisk);
                    if (unlockImage && cinderDisk.getImageStatus() == ImageStatus.LOCKED) {
                        cinderDisk.setImageStatus(ImageStatus.OK);
                    }
                    imageDao.update(cinderDisk.getImage());
                    updateQuota(cinderDisk);
                    break;
                case LUN:
                    // No specific update for LUN disk
                    break;
            }
            reloadDisks();
            setSucceeded(true);
            // If necessary set the new Storage QoS values on running VMs asynchronously
            liveUpdateDiskProfile();
            return null;
        }

        private void updateDeviceProperties() {
            if (updateReadOnlyRequested()) {
                vmDeviceForVm.setReadOnly(getDiskVmElement().isReadOnly());
                vmDeviceDao.update(vmDeviceForVm);
            }
            if ((getOldDiskVmElement().getDiskInterface() != getDiskVmElement().getDiskInterface()) || ((getOldDiskVmElement().isBoot() != getDiskVmElement().isBoot()) && (getDiskVmElement().getDiskInterface() == DiskInterface.IDE))) {
                vmDeviceForVm.setAddress("");
                vmDeviceDao.clearDeviceAddress(getOldDisk().getId());
            }
        }
    });
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 45 with DiskVmElement

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

the class AddDiskCommand method buildAddCinderDiskParameters.

private ActionParametersBase buildAddCinderDiskParameters() {
    AddDiskParameters parameters = new AddDiskParameters(new DiskVmElement(null, getVmId()), getParameters().getDiskInfo());
    parameters.setPlugDiskToVm(getParameters().getPlugDiskToVm());
    parameters.setStorageDomainId(getParameters().getStorageDomainId());
    parameters.setQuotaId(getQuotaId());
    parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
    if (getVm() != null) {
        parameters.setVmSnapshotId(snapshotDao.getId(getVmId(), SnapshotType.ACTIVE));
        parameters.setDiskVmElement(getParameters().getDiskVmElement());
    }
    return parameters;
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) AddDiskParameters(org.ovirt.engine.core.common.action.AddDiskParameters)

Aggregations

DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)91 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Test (org.junit.Test)26 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)23 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)22 Guid (org.ovirt.engine.core.compat.Guid)17 ArrayList (java.util.ArrayList)16 VM (org.ovirt.engine.core.common.businessentities.VM)12 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)11 HashMap (java.util.HashMap)8 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)8 Map (java.util.Map)7 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)7 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)7 ActionType (org.ovirt.engine.core.common.action.ActionType)6 AttachDetachVmDiskParameters (org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 VmDiskOperationParameterBase (org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)5 Collection (java.util.Collection)4