From 7d1dc97423e5005f4e0513fc86643286c5f42ad9 Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Thu, 22 Oct 2015 12:16:19 -0600 Subject: [PATCH] CLOUDSTACK-8985: Deleted volume's removed column not updated --- .../SolidFirePrimaryDataStoreDriver.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java index e9344265ae1..61e199c74cf 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java @@ -294,12 +294,20 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { @Override public long getUsedBytes(StoragePool storagePool) { + return getUsedBytes(storagePool, Long.MIN_VALUE); + } + + private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) { long usedSpace = 0; List lstVolumes = _volumeDao.findByPoolId(storagePool.getId(), null); if (lstVolumes != null) { for (VolumeVO volume : lstVolumes) { + if (volume.getId() == volumeIdToIgnore) { + continue; + } + VolumeDetailVO volumeDetail = _volumeDetailsDao.findDetail(volume.getId(), SolidFireUtil.VOLUME_SIZE); if (volumeDetail != null && volumeDetail.getValue() != null) { @@ -309,15 +317,21 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { } else { SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePool.getId(), _storagePoolDetailsDao); - long lVolumeId = Long.parseLong(volume.getFolder()); - SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getSolidFireVolume(sfConnection, lVolumeId); + try { + long lVolumeId = Long.parseLong(volume.getFolder()); - // SolidFireUtil.VOLUME_SIZE was introduced in 4.5. - // To be backward compatible with releases prior to 4.5, call updateVolumeDetails here. - // That way if SolidFireUtil.VOLUME_SIZE wasn't put in the volume_details table when the - // volume was initially created, it can be placed in volume_details here. - updateVolumeDetails(volume.getId(), sfVolume.getTotalSize()); + SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getSolidFireVolume(sfConnection, lVolumeId); + + // SolidFireUtil.VOLUME_SIZE was introduced in 4.5. + // To be backward compatible with releases prior to 4.5, call updateVolumeDetails here. + // That way if SolidFireUtil.VOLUME_SIZE wasn't put in the volume_details table when the + // volume was initially created, it can be placed in volume_details here. + updateVolumeDetails(volume.getId(), sfVolume.getTotalSize()); + } + catch (NumberFormatException ex) { + // can be ignored (the "folder" column didn't have a valid "long" in it (hasn't been placed there yet)) + } } } } @@ -519,8 +533,7 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId); - // getUsedBytes(StoragePool) will not include the volume to delete because it has already been deleted by this point - long usedBytes = getUsedBytes(storagePool); + long usedBytes = getUsedBytes(storagePool, volumeId); storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);