Search in sources :

Example 21 with KvmStoragePool

use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cloudstack by apache.

the class LibvirtGetStorageStatsCommandWrapper method execute.

@Override
public Answer execute(final GetStorageStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
    try {
        final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        final KVMStoragePool sp = storagePoolMgr.getStoragePool(command.getPooltype(), command.getStorageId(), true);
        if (sp == null) {
            return new GetStorageStatsAnswer(command, "no storage pool to get statistics from");
        }
        return new GetStorageStatsAnswer(command, sp.getCapacity(), sp.getUsed());
    } catch (final CloudRuntimeException e) {
        return new GetStorageStatsAnswer(command, e.toString());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 22 with KvmStoragePool

use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cloudstack by apache.

the class LibvirtGetVolumeStatsCommandWrapper method getVolumeStat.

private VolumeStatsEntry getVolumeStat(final LibvirtComputingResource libvirtComputingResource, final Connect conn, final String volumeUuid, final String storeUuid, final StoragePoolType poolType) throws LibvirtException {
    KVMStoragePool sourceKVMPool = libvirtComputingResource.getStoragePoolMgr().getStoragePool(poolType, storeUuid);
    if (sourceKVMPool == null) {
        return null;
    }
    KVMPhysicalDisk sourceKVMVolume = sourceKVMPool.getPhysicalDisk(volumeUuid);
    if (sourceKVMVolume == null) {
        return null;
    }
    return new VolumeStatsEntry(volumeUuid, sourceKVMVolume.getSize(), sourceKVMVolume.getVirtualSize());
}
Also used : KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)

Example 23 with KvmStoragePool

use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cloudstack by apache.

the class LibvirtCreateCommandWrapper method execute.

@Override
public Answer execute(final CreateCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final StorageFilerTO pool = command.getPool();
    final DiskProfile dskch = command.getDiskCharacteristics();
    KVMPhysicalDisk baseVol = null;
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    long disksize;
    try {
        final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        primaryPool = storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid());
        disksize = dskch.getSize();
        if (command.getTemplateUrl() != null) {
            if (primaryPool.getType() == StoragePoolType.CLVM) {
                vol = libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primaryPool, dskch.getPath());
            } else {
                baseVol = primaryPool.getPhysicalDisk(command.getTemplateUrl());
                vol = storagePoolMgr.createDiskFromTemplate(baseVol, dskch.getPath(), dskch.getProvisioningType(), primaryPool, baseVol.getSize(), 0);
            }
            if (vol == null) {
                return new Answer(command, false, " Can't create storage volume on storage pool");
            }
        } else {
            vol = primaryPool.createPhysicalDisk(dskch.getPath(), dskch.getProvisioningType(), dskch.getSize());
            if (vol == null) {
                return new Answer(command, false, " Can't create Physical Disk");
            }
        }
        final VolumeTO volume = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null);
        volume.setBytesReadRate(dskch.getBytesReadRate());
        volume.setBytesWriteRate(dskch.getBytesWriteRate());
        volume.setIopsReadRate(dskch.getIopsReadRate());
        volume.setIopsWriteRate(dskch.getIopsWriteRate());
        volume.setCacheMode(dskch.getCacheMode());
        return new CreateAnswer(command, volume);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: " + e.toString());
        return new CreateAnswer(command, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 24 with KvmStoragePool

use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cloudstack by apache.

the class LibvirtResizeVolumeCommandWrapper method execute.

@Override
public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String volid = command.getPath();
    final long newSize = command.getNewSize();
    final long currentSize = command.getCurrentSize();
    final String vmInstanceName = command.getInstanceName();
    final boolean shrinkOk = command.getShrinkOk();
    final StorageFilerTO spool = command.getPool();
    final String notifyOnlyType = LibvirtComputingResource.RESIZE_NOTIFY_ONLY;
    if (currentSize == newSize) {
        // nothing to do
        s_logger.info("No need to resize volume: current size " + toHumanReadableSize(currentSize) + " is same as new size " + toHumanReadableSize(newSize));
        return new ResizeVolumeAnswer(command, true, "success", currentSize);
    }
    try {
        final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        KVMStoragePool pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
        final KVMPhysicalDisk vol = pool.getPhysicalDisk(volid);
        final String path = vol.getPath();
        String type = notifyOnlyType;
        if (pool.getType() != StoragePoolType.RBD && pool.getType() != StoragePoolType.Linstor) {
            type = libvirtComputingResource.getResizeScriptType(pool, vol);
            if (type.equals("QCOW2") && shrinkOk) {
                return new ResizeVolumeAnswer(command, false, "Unable to shrink volumes of type " + type);
            }
        } else {
            s_logger.debug("Volume " + path + " is on a RBD/Linstor storage pool. No need to query for additional information.");
        }
        s_logger.debug("Resizing volume: " + path + ", from: " + toHumanReadableSize(currentSize) + ", to: " + toHumanReadableSize(newSize) + ", type: " + type + ", name: " + vmInstanceName + ", shrinkOk: " + shrinkOk);
        /* libvirt doesn't support resizing (C)LVM devices, and corrupts QCOW2 in some scenarios, so we have to do these via Bash script */
        if (pool.getType() != StoragePoolType.CLVM && pool.getType() != StoragePoolType.Linstor && vol.getFormat() != PhysicalDiskFormat.QCOW2) {
            s_logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume.");
            try {
                final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
                final Connect conn = libvirtUtilitiesHelper.getConnection();
                final StorageVol v = conn.storageVolLookupByPath(path);
                int flags = 0;
                if (conn.getLibVirVersion() > 1001000 && vol.getFormat() == PhysicalDiskFormat.RAW && pool.getType() != StoragePoolType.RBD) {
                    flags = 1;
                }
                if (shrinkOk) {
                    flags = 4;
                }
                v.resize(newSize, flags);
            } catch (final LibvirtException e) {
                return new ResizeVolumeAnswer(command, false, e.toString());
            }
        }
        s_logger.debug("Invoking resize script to handle type " + type);
        final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), s_logger);
        resizecmd.add("-s", String.valueOf(newSize));
        resizecmd.add("-c", String.valueOf(currentSize));
        resizecmd.add("-p", path);
        resizecmd.add("-t", type);
        resizecmd.add("-r", String.valueOf(shrinkOk));
        resizecmd.add("-v", vmInstanceName);
        final String result = resizecmd.execute();
        if (result != null) {
            if (type.equals(notifyOnlyType)) {
                return new ResizeVolumeAnswer(command, true, "Resize succeeded, but need reboot to notify guest");
            } else {
                return new ResizeVolumeAnswer(command, false, result);
            }
        }
        /* fetch new size as seen from libvirt, don't want to assume anything */
        pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
        pool.refresh();
        final long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
        s_logger.debug("after resize, size reports as: " + toHumanReadableSize(finalSize) + ", requested: " + toHumanReadableSize(newSize));
        return new ResizeVolumeAnswer(command, true, "success", finalSize);
    } catch (final CloudRuntimeException e) {
        final String error = "Failed to resize volume: " + e.getMessage();
        s_logger.debug(error);
        return new ResizeVolumeAnswer(command, false, error);
    }
}
Also used : Script(com.cloud.utils.script.Script) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 25 with KvmStoragePool

use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cloudstack by apache.

the class LibvirtMigrateVolumeCommandWrapper method execute.

@Override
public Answer execute(final MigrateVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    KVMStoragePoolManager storagePoolManager = libvirtComputingResource.getStoragePoolMgr();
    VolumeObjectTO srcVolumeObjectTO = (VolumeObjectTO) command.getSrcData();
    PrimaryDataStoreTO srcPrimaryDataStore = (PrimaryDataStoreTO) srcVolumeObjectTO.getDataStore();
    Map<String, String> srcDetails = command.getSrcDetails();
    String srcPath = srcDetails != null ? srcDetails.get(DiskTO.IQN) : srcVolumeObjectTO.getPath();
    VolumeObjectTO destVolumeObjectTO = (VolumeObjectTO) command.getDestData();
    PrimaryDataStoreTO destPrimaryDataStore = (PrimaryDataStoreTO) destVolumeObjectTO.getDataStore();
    Map<String, String> destDetails = command.getDestDetails();
    String destPath = destDetails != null && destDetails.get(DiskTO.IQN) != null ? destDetails.get(DiskTO.IQN) : (destVolumeObjectTO.getPath() != null ? destVolumeObjectTO.getPath() : UUID.randomUUID().toString());
    try {
        storagePoolManager.connectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath, srcDetails);
        KVMPhysicalDisk srcPhysicalDisk = storagePoolManager.getPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
        KVMStoragePool destPrimaryStorage = storagePoolManager.getStoragePool(destPrimaryDataStore.getPoolType(), destPrimaryDataStore.getUuid());
        storagePoolManager.connectPhysicalDisk(destPrimaryDataStore.getPoolType(), destPrimaryDataStore.getUuid(), destPath, destDetails);
        storagePoolManager.copyPhysicalDisk(srcPhysicalDisk, destPath, destPrimaryStorage, command.getWaitInMillSeconds());
    } catch (Exception ex) {
        return new MigrateVolumeAnswer(command, false, ex.getMessage(), null);
    } finally {
        try {
            storagePoolManager.disconnectPhysicalDisk(destPrimaryDataStore.getPoolType(), destPrimaryDataStore.getUuid(), destPath);
        } catch (Exception e) {
            LOGGER.warn("Unable to disconnect from the destination device.", e);
        }
        try {
            storagePoolManager.disconnectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
        } catch (Exception e) {
            LOGGER.warn("Unable to disconnect from the source device.", e);
        }
    }
    return new MigrateVolumeAnswer(command, true, null, destPath);
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Aggregations

Answer (com.cloud.agent.api.Answer)66 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)58 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)57 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)57 Test (org.junit.Test)57 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)47 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)46 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)41 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)40 StoragePool (com.cloud.storage.StoragePool)40 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 KvmPhysicalDisk (com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk)34 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)29 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AttachAnswer (com.cloud.storage.command.AttachAnswer)28 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)25 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)20 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)20