diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java index 192ae4636e9..3d2ca5b1d09 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java @@ -1230,13 +1230,13 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver { } org.apache.cloudstack.storage.datastore.api.Volume scaleIOVolume = client.getVolume(scaleIOVolumeId); - long newSizeInGB = newSizeInBytes / (1024 * 1024 * 1024); - long newSizeIn8gbBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0); + double newSizeInGB = newSizeInBytes / (1024.0 * 1024 * 1024); + long newSizeIn8GBBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0); - if (scaleIOVolume.getSizeInKb() == newSizeIn8gbBoundary << 20) { + if (scaleIOVolume.getSizeInKb() == newSizeIn8GBBoundary << 20) { logger.debug("No resize necessary at API"); } else { - scaleIOVolume = client.resizeVolume(scaleIOVolumeId, (int) newSizeIn8gbBoundary); + scaleIOVolume = client.resizeVolume(scaleIOVolumeId, (int) newSizeIn8GBBoundary); if (scaleIOVolume == null) { throw new CloudRuntimeException("Failed to resize volume: " + volumeInfo.getName()); } @@ -1362,12 +1362,12 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver { @Override public long getVolumeSizeRequiredOnPool(long volumeSize, Long templateSize, boolean isEncryptionRequired) { - long newSizeInGB = volumeSize / (1024 * 1024 * 1024); + double newSizeInGB = volumeSize / (1024.0 * 1024 * 1024); if (templateSize != null && isEncryptionRequired && needsExpansionForEncryptionHeader(templateSize, volumeSize)) { - newSizeInGB = (volumeSize + (1<<30)) / (1024 * 1024 * 1024); + newSizeInGB = (volumeSize + (1<<30)) / (1024.0 * 1024 * 1024); } - long newSizeIn8gbBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0); - return newSizeIn8gbBoundary * (1024 * 1024 * 1024); + long newSizeIn8GBBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0); + return newSizeIn8GBBoundary * (1024 * 1024 * 1024); } @Override diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java index 921dd3d4d9f..610b595ee05 100644 --- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java @@ -555,6 +555,18 @@ public class ScaleIOPrimaryDataStoreDriverTest { @Test public void testGetVolumeSizeRequiredOnPool() { + Assert.assertEquals(8L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 52428800, + null, + false)); + + Assert.assertEquals(8L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 52428800, + 52428800L, + true)); + Assert.assertEquals(16L * (1024 * 1024 * 1024), scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( 10L * (1024 * 1024 * 1024), diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java index d68e9cbd110..897b293f30d 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java @@ -139,6 +139,9 @@ public class StorPoolStorageAdaptor implements StorageAdaptor { } public static String getVolumeNameFromPath(final String volumeUuid, boolean tildeNeeded) { + if (volumeUuid == null) { + return null; + } if (volumeUuid.startsWith("/dev/storpool/")) { return volumeUuid.split("/")[3]; } else if (volumeUuid.startsWith("/dev/storpool-byid/")) {