public String getPathForVolumeUuid(String volumeUuid) { VolumeVO volume = volumeDao.findByUuid(volumeUuid); if (volume == null) { throw new CloudRuntimeException("Unable to find Volume for ID: " + volumeUuid); } return volume.getPath(); }
private boolean volumeExistsOnPrimary(VolumeVO vol) { Long poolId = vol.getPoolId(); if (poolId == null) { return false; } PrimaryDataStore primaryStore = dataStoreMgr.getPrimaryDataStore(poolId); if (primaryStore == null) { return false; } if (primaryStore.isManaged()) { return true; } String volumePath = vol.getPath(); if (volumePath == null || volumePath.trim().isEmpty()) { return false; } return true; }
@Override public void updateVolumeDiskChain(long volumeId, String path, String chainInfo) { VolumeVO vol = _volsDao.findById(volumeId); boolean needUpdate = false; // Volume path is not getting updated in the DB, need to find reason and fix the issue. if (vol.getPath() == null) { return; } if (!vol.getPath().equalsIgnoreCase(path)) { needUpdate = true; } if (chainInfo != null && (vol.getChainInfo() == null || !chainInfo.equalsIgnoreCase(vol.getChainInfo()))) { needUpdate = true; } if (needUpdate) { s_logger.info("Update volume disk chain info. vol: " + vol.getId() + ", " + vol.getPath() + " -> " + path + ", " + vol.getChainInfo() + " -> " + chainInfo); vol.setPath(path); vol.setChainInfo(chainInfo); _volsDao.update(volumeId, vol); } } }
@Override public String getPath() { if (dataStore.getRole() == DataStoreRole.Primary) { return volumeVO.getPath(); } else { DataObjectInStore objInStore = objectInStoreMgr.findObject(this, dataStore); if (objInStore != null) { return objInStore.getInstallPath(); } else { return null; } } }
volumeLocators.add(volume.getUuid()); } else if (volume.getFormat() == ImageFormat.VHD) { volumeLocators.add(volume.getPath()); } else if (volume.getFormat() == ImageFormat.OVA) { volumeLocators.add(volume.getChainInfo());
@Override public void prepareForMigration(VirtualMachineProfile vm, DeployDestination dest) { List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Preparing " + vols.size() + " volumes for " + vm); } for (VolumeVO vol : vols) { VolumeInfo volumeInfo = volFactory.getVolume(vol.getId()); DataTO volTO = volumeInfo.getTO(); DiskTO disk = storageMgr.getDiskWithThrottling(volTO, vol.getVolumeType(), vol.getDeviceId(), vol.getPath(), vm.getServiceOfferingId(), vol.getDiskOfferingId()); DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary); disk.setDetails(getDetails(volumeInfo, dataStore)); vm.addDisk(disk); } //if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) { if (vm.getType() == VirtualMachine.Type.User) { _tmpltMgr.prepareIsoForVmProfile(vm, dest); //DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO(); //DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO); //vm.addDisk(iso); } }
@Override public List<Command> finalizeExpungeVolumes(VirtualMachine vm) { List<Command> commands = new ArrayList<Command>(); List<VolumeVO> volumes = volumeDao.findByInstance(vm.getId()); // it's OK in this case to send a detach command to the host for a root volume as this // will simply lead to the SR that supports the root volume being removed if (volumes != null) { for (VolumeVO volume : volumes) { StoragePoolVO storagePool = storagePoolDao.findById(volume.getPoolId()); // storagePool should be null if we are expunging a volume that was never // attached to a VM that was started (the "trick" for storagePool to be null // is that none of the VMs this volume may have been attached to were ever started, // so the volume was never assigned to a storage pool) if (storagePool != null && storagePool.isManaged()) { DataTO volTO = volFactory.getVolume(volume.getId()).getTO(); DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType()); DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName()); cmd.setManaged(true); cmd.setStorageHost(storagePool.getHostAddress()); cmd.setStoragePort(storagePool.getPort()); cmd.set_iScsiName(volume.get_iScsiName()); commands.add(cmd); } } } return commands; }
private void syncDiskChainChange(final StartAnswer answer) { final VirtualMachineTO vmSpec = answer.getVirtualMachine(); for (final DiskTO disk : vmSpec.getDisks()) { if (disk.getType() != Volume.Type.ISO) { final VolumeObjectTO vol = (VolumeObjectTO)disk.getData(); final VolumeVO volume = _volsDao.findById(vol.getId()); // Use getPath() from VolumeVO to get a fresh copy of what's in the DB. // Before doing this, in a certain situation, getPath() from VolumeObjectTO // returned null instead of an actual path (because it was out of date with the DB). if(vol.getPath() != null) { volumeMgr.updateVolumeDiskChain(vol.getId(), vol.getPath(), vol.getChainInfo()); } else { volumeMgr.updateVolumeDiskChain(vol.getId(), volume.getPath(), vol.getChainInfo()); } } } }
if (host != null && host.getHypervisorType() == HypervisorType.KVM && volumeToAttachStoragePool.isManaged() && volumeToAttach.getPath() == null) { volumeToAttach.setPath(volumeToAttach.get_iScsiName()); DiskTO disk = storageMgr.getDiskWithThrottling(volTO, volumeToAttach.getVolumeType(), deviceId, volumeToAttach.getPath(), vm.getServiceOfferingId(), volumeToAttach.getDiskOfferingId()); if (volumeToAttachStoragePool.isManaged() && volumeToAttach.getPath() == null) { volumeToAttach.setPath(answer.getDisk().getPath()); if (vm.getHypervisorType() == HypervisorType.KVM && volumeToAttachStoragePool.isManaged() && volumeToAttach.getPath() == null) { volumeToAttach.setPath(volumeToAttach.get_iScsiName());
@Override public void resizeVolumeOnHypervisor(long volumeId, long newSize, long destHostId, String instanceName) { final String errMsg = "Resize command failed"; try { Answer answer = null; Host destHost = _hostDao.findById(destHostId); EndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(destHost); if (ep != null) { VolumeVO volume = volDao.findById(volumeId); PrimaryDataStore primaryDataStore = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId()); ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(volume.getPath(), new StorageFilerTO(primaryDataStore), volume.getSize(), newSize, true, instanceName, primaryDataStore.isManaged(), volume.get_iScsiName()); answer = ep.sendMessage(resizeCmd); } else { throw new CloudRuntimeException("Could not find a remote endpoint to send command to. Check if host or SSVM is down."); } if (answer == null || !answer.getResult()) { throw new CloudRuntimeException(answer != null ? answer.getDetails() : errMsg); } } catch (Exception e) { throw new CloudRuntimeException(errMsg, e); } }
VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid()); if (vol != null) { s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath()); vol.setPath(snapshotTO.getVolume().getPath());
DiskTO disk = new DiskTO(volumeInfo.getTO(), root.getDeviceId(), root.getPath(), root.getVolumeType());
primaryStorageSearch.select("sum", Func.SUM, primaryStorageSearch.entity().getSize()); primaryStorageSearch.and("accountId", primaryStorageSearch.entity().getAccountId(), Op.EQ); primaryStorageSearch.and().op("path", primaryStorageSearch.entity().getPath(), Op.NNULL); primaryStorageSearch.or("states", primaryStorageSearch.entity().getState(), Op.IN); primaryStorageSearch.cp(); primaryStorageSearch2.or("virtualRouterVmIds", primaryStorageSearch2.entity().getInstanceId(), Op.NIN); primaryStorageSearch2.cp(); primaryStorageSearch2.and().op("path", primaryStorageSearch2.entity().getPath(), Op.NNULL); primaryStorageSearch2.or("states", primaryStorageSearch2.entity().getState(), Op.IN); primaryStorageSearch2.cp(); secondaryStorageSearch.select("sum", Func.SUM, secondaryStorageSearch.entity().getSize()); secondaryStorageSearch.and("accountId", secondaryStorageSearch.entity().getAccountId(), Op.EQ); secondaryStorageSearch.and("path", secondaryStorageSearch.entity().getPath(), Op.NULL); secondaryStorageSearch.and("states", secondaryStorageSearch.entity().getState(), Op.NIN); secondaryStorageSearch.and("isRemoved", secondaryStorageSearch.entity().getRemoved(), Op.NULL);