private Map<String, String> getVolumeAttributes(VolumeInfo volumeInfo) { Map<String, String> mapAttributes = new HashMap<>(); mapAttributes.put(SolidFireUtil.CloudStackVolumeId, String.valueOf(volumeInfo.getId())); mapAttributes.put(SolidFireUtil.CloudStackVolumeSize, NumberFormat.getInstance().format(volumeInfo.getSize())); return mapAttributes; }
@Override public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject dataObject, StoragePool pool) { VolumeInfo volume = (VolumeInfo)dataObject; long volumeSize = volume.getSize(); Integer hypervisorSnapshotReserve = volume.getHypervisorSnapshotReserve(); if (hypervisorSnapshotReserve != null) { if (hypervisorSnapshotReserve < 25) { hypervisorSnapshotReserve = 25; } volumeSize += volumeSize * (hypervisorSnapshotReserve / 100f); } return volumeSize; }
private Map<String, String> getDetails(VolumeInfo volumeInfo, DataStore dataStore) { Map<String, String> details = new HashMap<String, String>(); StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId()); details.put(DiskTO.MANAGED, String.valueOf(storagePool.isManaged())); details.put(DiskTO.STORAGE_HOST, storagePool.getHostAddress()); details.put(DiskTO.STORAGE_PORT, String.valueOf(storagePool.getPort())); details.put(DiskTO.VOLUME_SIZE, String.valueOf(volumeInfo.getSize())); details.put(DiskTO.IQN, volumeInfo.get_iScsiName()); details.put(DiskTO.MOUNT_POINT, volumeInfo.get_iScsiName()); VolumeVO volume = _volumeDao.findById(volumeInfo.getId()); details.put(DiskTO.PROTOCOL_TYPE, (volume.getPoolType() != null) ? volume.getPoolType().toString() : null); ChapInfo chapInfo = volService.getChapInfo(volumeInfo, dataStore); if (chapInfo != null) { details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername()); details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret()); details.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername()); details.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret()); } return details; }
private VolumeInfo copyVolume(StoragePool rootDiskPool, VolumeInfo volume, VirtualMachine vm, VirtualMachineTemplate rootDiskTmplt, DataCenter dcVO, Pod pod, DiskOffering diskVO, ServiceOffering svo, HypervisorType rootDiskHyperType) throws NoTransitionException { if (!isSupportedImageFormatForCluster(volume, rootDiskHyperType)) { throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " + volume.getFormat().getFileExtension() + " is not compatible with the vm hypervisor type"); } VolumeInfo volumeOnPrimary = copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePool>(), volume.getSize(), rootDiskHyperType); return volumeOnPrimary; }
/** * We will check if the given volume is in the secondary storage. If the volume is not in the primary storage, we do nothing here. * If it is, we will execute an asynchronous call to delete it there. Then, we decrement the {@link ResourceType#secondary_storage} for the account that owns the volume. */ protected void expungeVolumesInSecondaryStorageIfNeeded(VolumeVO volume) throws InterruptedException, ExecutionException { VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image); if (volOnSecondary != null) { s_logger.info("Expunging volume " + volume.getId() + " from secondary data store"); AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary); future2.get(); _resourceLimitMgr.decrementResourceCount(volOnSecondary.getAccountId(), ResourceType.secondary_storage, volOnSecondary.getSize()); } }
@Override public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject dataObject, StoragePool pool) { long volumeSize = 0; if (dataObject.getType() == DataObjectType.VOLUME) { VolumeInfo volume = (VolumeInfo)dataObject; volumeSize = getVolumeSizeIncludingHypervisorSnapshotReserve(volume.getSize(), volume.getHypervisorSnapshotReserve()); } else if (dataObject.getType() == DataObjectType.TEMPLATE) { TemplateInfo templateInfo = (TemplateInfo)dataObject; // TemplateInfo sometimes has a size equal to null. long templateSize = templateInfo.getSize() != null ? templateInfo.getSize() : 0; if (templateInfo.getHypervisorType() == Hypervisor.HypervisorType.KVM) { volumeSize = templateSize; } else { volumeSize = (long)(templateSize + templateSize * (LOWEST_HYPERVISOR_SNAPSHOT_RESERVE / 100f)); } } return Math.max(volumeSize, SolidFireUtil.MIN_VOLUME_SIZE); }
details.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
null, null, snapshotStoreRef.getPhysicalSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getPhysicalSize())); } catch (Exception e) { s_logger.debug("post process snapshot failed", e); _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize())); throw cre; } catch (Exception e) { _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize())); throw new CloudRuntimeException("Failed to create snapshot", e);
protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId, Long vmId) throws StorageUnavailableException { VolumeInfo createdVolume = null; SnapshotVO snapshot = _snapshotDao.findById(snapshotId); snapshot.getVolumeId(); UserVmVO vm = null; if (vmId != null) { vm = _userVmDao.findById(vmId); } // sync old snapshots to region store if necessary createdVolume = _volumeMgr.createVolumeFromSnapshot(volume, snapshot, vm); VolumeVO volumeVo = _volsDao.findById(createdVolume.getId()); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, createdVolume.getAccountId(), createdVolume.getDataCenterId(), createdVolume.getId(), createdVolume.getName(), createdVolume.getDiskOfferingId(), null, createdVolume.getSize(), Volume.class.getName(), createdVolume.getUuid(), volumeVo.isDisplayVolume()); return volumeVo; }
if (freshSnapshot != null) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
@Override public VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm, VolumeInfo volume, HypervisorType rootDiskHyperType, StoragePool storagePool) throws NoTransitionException { VirtualMachineTemplate rootDiskTmplt = _entityMgr.findById(VirtualMachineTemplate.class, vm.getTemplateId()); DataCenter dcVO = _entityMgr.findById(DataCenter.class, vm.getDataCenterId()); Pod pod = _entityMgr.findById(Pod.class, storagePool.getPodId()); ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId()); DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId()); Long clusterId = storagePool.getClusterId(); VolumeInfo vol = null; if (volume.getState() == Volume.State.Allocated) { vol = createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePool>(), volume.getSize(), rootDiskHyperType); } else if (volume.getState() == Volume.State.Uploaded) { vol = copyVolume(storagePool, volume, vm, rootDiskTmplt, dcVO, pod, diskVO, svo, rootDiskHyperType); if (vol != null) { // Moving of Volume is successful, decrement the volume resource count from secondary for an account and increment it into primary storage under same account. _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, volume.getSize()); _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.getSize()); } } if (vol == null) { throw new CloudRuntimeException("Volume shouldn't be null " + volume.getId()); } VolumeVO volVO = _volsDao.findById(vol.getId()); if (volVO.getFormat() == null) { volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType)); } _volsDao.update(volVO.getId(), volVO); return volFactory.getVolume(volVO.getId()); }
long newSize = payload.newSize != null ? payload.newSize : volumeInfo.getSize();
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize()).longValue()); } catch (ResourceAllocationException e) { if (snapshotType != Type.MANUAL) { (short)snapshotType.ordinal(), snapshotType.name(), volume.getSize(), volume.getMinIops(), volume.getMaxIops(), hypervisorType, locationType); _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize())); return snapshot;
long capacityIops = storagePool.getCapacityIops(); usedBytes -= volumeInfo.getSize(); capacityIops += volumeInfo.getMaxIops();
@Override public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) { String iqn = null; String errorMessage = null; if (dataObject.getType() != DataObjectType.VOLUME) { errorMessage = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; } else { VolumeInfo volumeInfo = (VolumeInfo) dataObject; long storagePoolId = dataStore.getId(); NexentaStorAppliance appliance = getNexentaStorAppliance(storagePoolId); // TODO: maybe we should use md5(volume name) as volume name NexentaStorZvol zvol = (NexentaStorZvol) appliance.createVolume(volumeInfo.getName(), volumeInfo.getSize()); iqn = zvol.getIqn(); VolumeVO volume = this._volumeDao.findById(volumeInfo.getId()); volume.set_iScsiName(iqn); volume.setFolder(zvol.getName()); volume.setPoolType(Storage.StoragePoolType.IscsiLUN); volume.setPoolId(storagePoolId); _volumeDao.update(volume.getId(), volume); StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId); long capacityBytes = storagePool.getCapacityBytes(); long usedBytes = storagePool.getUsedBytes(); usedBytes += volumeInfo.getSize(); storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes); _storagePoolDao.update(storagePoolId, storagePool); } CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errorMessage == null, errorMessage)); result.setResult(errorMessage); callback.complete(result); }
VolumeObjectTO newVolume = new VolumeObjectTO(); newVolume.setSize(volumeInfo.getSize()); newVolume.setPath(volumeInfo.getPath()); newVolume.setFormat(volumeInfo.getFormat());
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.primary_storage, volumeToAttach.getSize()); } catch (ResourceAllocationException e) { s_logger.error("primary storage resource limit check failed", e);
public VolumeObjectTO(VolumeInfo volume) { uuid = volume.getUuid(); path = volume.getPath(); accountId = volume.getAccountId(); if (volume.getDataStore() != null) { dataStore = volume.getDataStore().getTO(); } else { dataStore = null; } vmName = volume.getAttachedVmName(); size = volume.getSize(); setVolumeId(volume.getId()); chainInfo = volume.getChainInfo(); volumeType = volume.getVolumeType(); name = volume.getName(); setId(volume.getId()); format = volume.getFormat(); provisioningType = volume.getProvisioningType(); bytesReadRate = volume.getBytesReadRate(); bytesWriteRate = volume.getBytesWriteRate(); iopsReadRate = volume.getIopsReadRate(); iopsWriteRate = volume.getIopsWriteRate(); cacheMode = volume.getCacheMode(); hypervisorType = volume.getHypervisorType(); setDeviceId(volume.getDeviceId()); }
s_logger.debug("Failed to backup snapshot from vm snapshot", e); _resourceLimitMgr.decrementResourceCount(snapshotOwnerId, ResourceType.snapshot); _resourceLimitMgr.decrementResourceCount(snapshotOwnerId, ResourceType.secondary_storage, new Long(volume.getSize())); throw new CloudRuntimeException("Failed to backup snapshot from vm snapshot", e);
VolumeObjectTO newVolume = new VolumeObjectTO(); newVolume.setSize(volumeInfo.getSize()); newVolume.setPath(volumeInfo.get_iScsiName()); newVolume.setFormat(volumeInfo.getFormat());