Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
Expand All @@ -37,6 +38,7 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -45,8 +47,6 @@

import javax.inject.Inject;

import com.google.common.collect.Sets;
import com.cloud.vm.UserVmManager;
import org.apache.cloudstack.annotation.AnnotationService;
import org.apache.cloudstack.annotation.dao.AnnotationDao;
import org.apache.cloudstack.api.ApiConstants;
Expand Down Expand Up @@ -229,11 +229,11 @@
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.VMInstanceDao;
import java.math.BigInteger;
import java.util.UUID;
import com.google.common.collect.Sets;

@Component
public class StorageManagerImpl extends ManagerBase implements StorageManager, ClusterManagerListener, Configurable {
Expand All @@ -249,8 +249,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Inject
protected ConfigurationManager _configMgr;
@Inject
protected VolumeDao _volsDao;
@Inject
private VolumeDataStoreDao _volumeDataStoreDao;
@Inject
protected HostDao _hostDao;
Expand Down Expand Up @@ -299,7 +297,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Inject
protected HypervisorGuruManager _hvGuruMgr;
@Inject
protected VolumeDao _volumeDao;
protected VolumeDao volumeDao;
@Inject
ConfigurationDao _configDao;
@Inject
Expand Down Expand Up @@ -372,7 +370,7 @@ public void setDiscoverers(List<StoragePoolDiscoverer> discoverers) {
public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, boolean cancelPreviousShare) throws StorageUnavailableException {

// if pool is in maintenance and it is the ONLY pool available; reject
List<VolumeVO> rootVolForGivenVm = _volsDao.findByInstanceAndType(vm.getId(), Type.ROOT);
List<VolumeVO> rootVolForGivenVm = volumeDao.findByInstanceAndType(vm.getId(), Type.ROOT);
if (rootVolForGivenVm != null && rootVolForGivenVm.size() > 0) {
boolean isPoolAvailable = isPoolAvailable(rootVolForGivenVm.get(0).getPoolId());
if (!isPoolAvailable) {
Expand Down Expand Up @@ -436,7 +434,7 @@ public boolean isLocalStorageActiveOnHost(Long hostId) {
for (StoragePoolHostVO storagePoolHostRef : storagePoolHostRefs) {
StoragePoolVO PrimaryDataStoreVO = _storagePoolDao.findById(storagePoolHostRef.getPoolId());
if (PrimaryDataStoreVO.getPoolType() == StoragePoolType.LVM || PrimaryDataStoreVO.getPoolType() == StoragePoolType.EXT) {
SearchBuilder<VolumeVO> volumeSB = _volsDao.createSearchBuilder();
SearchBuilder<VolumeVO> volumeSB = volumeDao.createSearchBuilder();
volumeSB.and("poolId", volumeSB.entity().getPoolId(), SearchCriteria.Op.EQ);
volumeSB.and("removed", volumeSB.entity().getRemoved(), SearchCriteria.Op.NULL);
volumeSB.and("state", volumeSB.entity().getState(), SearchCriteria.Op.NIN);
Expand All @@ -450,7 +448,7 @@ public boolean isLocalStorageActiveOnHost(Long hostId) {
volumeSC.setParameters("state", Volume.State.Expunging, Volume.State.Destroy);
volumeSC.setJoinParameters("activeVmSB", "state", State.Starting, State.Running, State.Stopping, State.Migrating);

List<VolumeVO> volumes = _volsDao.search(volumeSC, null);
List<VolumeVO> volumes = volumeDao.search(volumeSC, null);
if (volumes.size() > 0) {
return true;
}
Expand Down Expand Up @@ -598,7 +596,7 @@ public boolean configure(String name, Map<String, Object> params) {

StoragePoolSearch = _vmInstanceDao.createSearchBuilder();

SearchBuilder<VolumeVO> volumeSearch = _volumeDao.createSearchBuilder();
SearchBuilder<VolumeVO> volumeSearch = volumeDao.createSearchBuilder();
volumeSearch.and("volumeType", volumeSearch.entity().getVolumeType(), SearchCriteria.Op.EQ);
volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
volumeSearch.and("state", volumeSearch.entity().getState(), SearchCriteria.Op.EQ);
Expand Down Expand Up @@ -1035,10 +1033,10 @@ private boolean checkIfDataStoreClusterCanbeDeleted(StoragePoolVO sPool, boolean
List<StoragePoolVO> childStoragePools = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(sPool.getId());
boolean canDelete = true;
for (StoragePoolVO childPool : childStoragePools) {
Pair<Long, Long> vlms = _volsDao.getCountAndTotalByPool(childPool.getId());
Pair<Long, Long> vlms = volumeDao.getCountAndTotalByPool(childPool.getId());
if (forced) {
if (vlms.first() > 0) {
Pair<Long, Long> nonDstrdVlms = _volsDao.getNonDestroyedCountAndTotalByPool(childPool.getId());
Pair<Long, Long> nonDstrdVlms = volumeDao.getNonDestroyedCountAndTotalByPool(childPool.getId());
if (nonDstrdVlms.first() > 0) {
canDelete = false;
break;
Expand All @@ -1055,15 +1053,15 @@ private boolean checkIfDataStoreClusterCanbeDeleted(StoragePoolVO sPool, boolean
}

private boolean deleteDataStoreInternal(StoragePoolVO sPool, boolean forced) {
Pair<Long, Long> vlms = _volsDao.getCountAndTotalByPool(sPool.getId());
Pair<Long, Long> vlms = volumeDao.getCountAndTotalByPool(sPool.getId());
if (forced) {
if (vlms.first() > 0) {
Pair<Long, Long> nonDstrdVlms = _volsDao.getNonDestroyedCountAndTotalByPool(sPool.getId());
Pair<Long, Long> nonDstrdVlms = volumeDao.getNonDestroyedCountAndTotalByPool(sPool.getId());
if (nonDstrdVlms.first() > 0) {
throw new CloudRuntimeException("Cannot delete pool " + sPool.getName() + " as there are associated " + "non-destroyed vols for this pool");
}
// force expunge non-destroyed volumes
List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed();
List<VolumeVO> vols = volumeDao.listVolumesToBeDestroyed();
for (VolumeVO vol : vols) {
AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volFactory.getVolume(vol.getId()));
try {
Expand Down Expand Up @@ -1326,7 +1324,7 @@ public void cleanupStorage(boolean recurring) {
}
cleanupSecondaryStorage(recurring);

List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - ((long)StorageCleanupDelay.value() << 10)));
List<VolumeVO> vols = volumeDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - ((long)StorageCleanupDelay.value() << 10)));
for (VolumeVO vol : vols) {
if (Type.ROOT.equals(vol.getVolumeType())) {
VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(vol.getInstanceId());
Expand Down Expand Up @@ -1375,7 +1373,7 @@ public void cleanupStorage(boolean recurring) {
// destroy uploaded volumes in abandoned/error state
List<VolumeDataStoreVO> volumeDataStores = _volumeDataStoreDao.listByVolumeState(Volume.State.UploadError, Volume.State.UploadAbandoned);
for (VolumeDataStoreVO volumeDataStore : volumeDataStores) {
VolumeVO volume = _volumeDao.findById(volumeDataStore.getVolumeId());
VolumeVO volume = volumeDao.findById(volumeDataStore.getVolumeId());
if (volume == null) {
s_logger.warn("Uploaded volume with id " + volumeDataStore.getVolumeId() + " not found, so cannot be destroyed");
continue;
Expand Down Expand Up @@ -1948,7 +1946,7 @@ private void handleRemoveChildStoragePoolFromDatastoreCluster(Set<String> childD

for (String childDatastoreUUID : childDatastoreUUIDs) {
StoragePoolVO dataStoreVO = _storagePoolDao.findPoolByUUID(childDatastoreUUID);
List<VolumeVO> allVolumes = _volumeDao.findByPoolId(dataStoreVO.getId());
List<VolumeVO> allVolumes = volumeDao.findByPoolId(dataStoreVO.getId());
allVolumes.removeIf(volumeVO -> volumeVO.getInstanceId() == null);
allVolumes.removeIf(volumeVO -> volumeVO.getState() != Volume.State.Ready);
for (VolumeVO volume : allVolumes) {
Expand Down Expand Up @@ -1984,7 +1982,7 @@ private void handleRemoveChildStoragePoolFromDatastoreCluster(Set<String> childD
volume.getUuid() + "Host=" + hostId;

// check for the changed details of volume and update database
VolumeVO volumeVO = _volumeDao.findById(volumeId);
VolumeVO volumeVO = volumeDao.findById(volumeId);
String datastoreName = answer.getContextParam("datastoreName");
if (datastoreName != null) {
StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
Expand All @@ -2005,7 +2003,7 @@ private void handleRemoveChildStoragePoolFromDatastoreCluster(Set<String> childD
volumeVO.setChainInfo(chainInfo);
}

_volumeDao.update(volumeVO.getId(), volumeVO);
volumeDao.update(volumeVO.getId(), volumeVO);
}
dataStoreVO.setParent(0L);
_storagePoolDao.update(dataStoreVO.getId(), dataStoreVO);
Expand Down Expand Up @@ -2426,14 +2424,14 @@ public boolean storagePoolHasEnoughSpace(List<Pair<Volume, DiskProfile>> volumeD
// might be clearer that this "volume" in "volumeDiskProfilesList" still might have an old value for hv_ss_reverse.
Volume volume = volumeDiskProfilePair.first();
DiskProfile diskProfile = volumeDiskProfilePair.second();
VolumeVO volumeVO = _volumeDao.findById(volume.getId());
VolumeVO volumeVO = volumeDao.findById(volume.getId());

if (volumeVO.getHypervisorSnapshotReserve() == null) {
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
volService.updateHypervisorSnapshotReserveForVolume(getDiskOfferingVO(volumeVO), volumeVO.getId(), getHypervisorType(volumeVO));

// hv_ss_reserve field might have been updated; refresh from DB to make use of it in getDataObjectSizeIncludingHypervisorSnapshotReserve
volumeVO = _volumeDao.findById(volume.getId());
volumeVO = volumeDao.findById(volume.getId());
}

// this if statement should resolve to true at most once per execution of the for loop its contained within (for a root disk that is
Expand Down Expand Up @@ -3271,9 +3269,9 @@ public void cleanupDownloadUrls() {
if (activeVolumeIds.contains(volumeId)) {
continue;
}
Volume volume = _volumeDao.findById(volumeId);
Volume volume = volumeDao.findById(volumeId);
if (volume != null && volume.getState() == Volume.State.Expunged) {
_volumeDao.remove(volumeId);
volumeDao.remove(volumeId);
}
}

Expand Down