Search in sources :

Example 56 with DiskVmElement

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

the class DiskVmElementDaoTest method testVmElementDiskPluggedStatus.

@Test
public void testVmElementDiskPluggedStatus() {
    DiskVmElement dvePlugged = dao.get(new VmDeviceId(PLUGGED_DISK_ID, FixturesTool.VM_RHEL5_POOL_57));
    assertTrue(dvePlugged.isPlugged());
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Test(org.junit.Test)

Example 57 with DiskVmElement

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

the class DiskVmElementDaoTest method testVmElementDiskLogicalName.

@Test
public void testVmElementDiskLogicalName() {
    DiskVmElement dveWithLogicalName = dao.get(new VmDeviceId(PLUGGED_DISK_ID, FixturesTool.VM_RHEL5_POOL_57));
    assertEquals("logical_name", dveWithLogicalName.getLogicalName());
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Test(org.junit.Test)

Example 58 with DiskVmElement

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

the class DiskVmElementDaoTest method testGetFilteredWithoutPermissions.

@Test
public void testGetFilteredWithoutPermissions() {
    DiskVmElement result = dao.get(getExistingEntityId(), UNPRIVILEGED_USER_ID, true);
    assertNull(result);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Test(org.junit.Test)

Example 59 with DiskVmElement

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

the class VmInfoBuildUtils method getVmDeviceUnitMapForScsiDisks.

protected Map<Integer, Map<VmDevice, Integer>> getVmDeviceUnitMapForScsiDisks(VM vm, DiskInterface scsiInterface, boolean reserveFirstTwoLuns, boolean reserveForScsiCd) {
    List<Disk> disks = getSortedDisks(vm);
    Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = new HashMap<>();
    LinkedList<VmDevice> vmDeviceList = new LinkedList<>();
    for (Disk disk : disks) {
        DiskVmElement dve = disk.getDiskVmElementForVm(vm.getId());
        if (dve.getDiskInterface() == scsiInterface) {
            VmDevice vmDevice = getVmDeviceByDiskId(disk.getId(), vm.getId());
            Map<String, String> address = StringMapUtils.string2Map(vmDevice.getAddress());
            String unitStr = address.get(VdsProperties.Unit);
            String controllerStr = address.get(VdsProperties.Controller);
            // Otherwise, adding to 'vmDeviceList' for setting the unit property later.
            if (StringUtils.isNotEmpty(unitStr) && StringUtils.isNotEmpty(controllerStr)) {
                Integer controllerInt = Integer.valueOf(controllerStr);
                boolean controllerOutOfRange = controllerInt >= vm.getNumOfIoThreads() + getDefaultVirtioScsiIndex(vm);
                boolean ioThreadsEnabled = vm.getNumOfIoThreads() > 0 && FeatureSupported.virtioScsiIoThread(vm.getCompatibilityVersion());
                if ((ioThreadsEnabled && !controllerOutOfRange) || (controllerInt == getDefaultVirtioScsiIndex(vm))) {
                    if (!vmDeviceUnitMap.containsKey(controllerInt)) {
                        vmDeviceUnitMap.put(controllerInt, new HashMap<>());
                    }
                    vmDeviceUnitMap.get(controllerInt).put(vmDevice, Integer.valueOf(unitStr));
                } else {
                    // controller id not correct, generate the address again later
                    vmDevice.setAddress(null);
                    vmDeviceList.add(vmDevice);
                }
            } else {
                vmDeviceList.add(vmDevice);
            }
        }
    }
    // Find available unit (disk's index in VirtIO-SCSI controller) for disks with empty address\
    IntStream.range(0, vmDeviceList.size()).forEach(index -> {
        VmDevice vmDevice = vmDeviceList.get(index);
        // TODO: consider changing this so that it will search for the next available and
        // less used controller instead of always starting from index.
        int controller = getControllerForScsiDisk(vmDevice, vm, index);
        if (!vmDeviceUnitMap.containsKey(controller)) {
            vmDeviceUnitMap.put(controller, new HashMap<>());
        }
        int unit = getAvailableUnitForScsiDisk(vmDeviceUnitMap.get(controller), reserveFirstTwoLuns, reserveForScsiCd && controller == 0);
        vmDeviceUnitMap.get(controller).put(vmDevice, unit);
    });
    return vmDeviceUnitMap;
}
Also used : HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) Map(java.util.Map) HashMap(java.util.HashMap)

Example 60 with DiskVmElement

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

the class VmInfoBuilderImpl method buildVmDrives.

@Override
public void buildVmDrives() {
    boolean bootDiskFound = false;
    List<Disk> disks = vmInfoBuildUtils.getSortedDisks(vm);
    Map<Integer, Map<VmDevice, Integer>> vmDeviceVirtioScsiUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForVirtioScsiDisks(vm);
    Map<Integer, Map<VmDevice, Integer>> vmDeviceSpaprVscsiUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForSpaprScsiDisks(vm);
    Map<Guid, StorageQos> qosCache = new HashMap<>();
    int pinnedDriveIndex = 0;
    for (Disk disk : disks) {
        Map<String, Object> struct = new HashMap<>();
        // get vm device for this disk from DB
        VmDevice vmDevice = vmInfoBuildUtils.getVmDeviceByDiskId(disk.getId(), vm.getId());
        DiskVmElement dve = disk.getDiskVmElementForVm(vm.getId());
        // skip unmanaged devices (handled separately)
        if (!vmDevice.isManaged()) {
            continue;
        }
        if (vmDevice.isPlugged()) {
            struct.put(VdsProperties.Type, vmDevice.getType().getValue());
            struct.put(VdsProperties.Device, vmDevice.getDevice());
            switch(dve.getDiskInterface()) {
                case IDE:
                    struct.put(VdsProperties.INTERFACE, VdsProperties.Ide);
                    break;
                case VirtIO:
                    struct.put(VdsProperties.INTERFACE, VdsProperties.Virtio);
                    int pinTo = vmInfoBuildUtils.pinToIoThreads(vm, pinnedDriveIndex++);
                    if (pinTo > 0) {
                        vmDevice.getSpecParams().put(VdsProperties.pinToIoThread, pinTo);
                    }
                    break;
                case VirtIO_SCSI:
                    // set device type as 'lun' (instead of 'disk') and set the specified SGIO.
                    if (disk.getDiskStorageType() == DiskStorageType.LUN && disk.isScsiPassthrough()) {
                        struct.put(VdsProperties.Device, VmDeviceType.LUN.getName());
                        struct.put(VdsProperties.Sgio, disk.getSgio().toString().toLowerCase());
                    }
                case SPAPR_VSCSI:
                    struct.put(VdsProperties.INTERFACE, VdsProperties.Scsi);
                    vmInfoBuildUtils.calculateAddressForScsiDisk(vm, disk, vmDevice, vmDeviceSpaprVscsiUnitMap, vmDeviceVirtioScsiUnitMap);
                    break;
                default:
                    logUnsupportedInterfaceType();
                    break;
            }
            // Insure that boot disk is created first
            if (!bootDiskFound && dve.isBoot()) {
                bootDiskFound = true;
                struct.put(VdsProperties.Index, getBootableDiskIndex(disk));
            }
            if (FeatureSupported.passDiscardSupported(vm.getCompatibilityVersion())) {
                struct.put(VdsProperties.DISCARD, dve.isPassDiscard());
            }
            vmInfoBuildUtils.addAddress(vmDevice, struct);
            switch(disk.getDiskStorageType()) {
                case IMAGE:
                    DiskImage diskImage = (DiskImage) disk;
                    struct.put(VdsProperties.DiskType, vmInfoBuildUtils.getDiskType(vm, diskImage));
                    struct.put(VdsProperties.PoolId, diskImage.getStoragePoolId().toString());
                    struct.put(VdsProperties.DomainId, diskImage.getStorageIds().get(0).toString());
                    struct.put(VdsProperties.ImageId, diskImage.getId().toString());
                    struct.put(VdsProperties.VolumeId, diskImage.getImageId().toString());
                    struct.put(VdsProperties.Format, diskImage.getVolumeFormat().toString().toLowerCase());
                    struct.put(VdsProperties.PropagateErrors, disk.getPropagateErrors().toString().toLowerCase());
                    if (!qosCache.containsKey(diskImage.getDiskProfileId())) {
                        qosCache.put(diskImage.getDiskProfileId(), vmInfoBuildUtils.loadStorageQos(diskImage));
                    }
                    vmInfoBuildUtils.handleIoTune(vmDevice, qosCache.get(diskImage.getDiskProfileId()));
                    break;
                case LUN:
                    LunDisk lunDisk = (LunDisk) disk;
                    struct.put(VdsProperties.Guid, lunDisk.getLun().getLUNId());
                    struct.put(VdsProperties.Format, VolumeFormat.RAW.toString().toLowerCase());
                    struct.put(VdsProperties.PropagateErrors, PropagateErrors.Off.toString().toLowerCase());
                    break;
                case CINDER:
                    vmInfoBuildUtils.buildCinderDisk((CinderDisk) disk, struct);
                    break;
            }
            struct.put(VdsProperties.Shareable, (vmDevice.getSnapshotId() != null) ? VdsProperties.Transient : String.valueOf(disk.isShareable()));
            struct.put(VdsProperties.Optional, Boolean.FALSE.toString());
            struct.put(VdsProperties.ReadOnly, String.valueOf(vmDevice.getReadOnly()));
            struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
            struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
            devices.add(struct);
            bootableDevices.add(vmDevice);
        }
    }
    ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new CreateAdditionalControllers(devices));
}
Also used : StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) HashMap(java.util.HashMap) CreateAdditionalControllers(org.ovirt.engine.core.vdsbroker.architecture.CreateAdditionalControllers) Guid(org.ovirt.engine.core.compat.Guid) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) 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) Map(java.util.Map) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

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