Skip to content

Commit 1e9ae76

Browse files
sureshanapartidhslove
authored andcommitted
Fix to create instances with smaller templates (< 1 GB) on PowerFlex/ScaleIO storage (apache#11211)
* Fix to create instances with smaller templates (< 1 GB) on PowerFlex/ScaleIO storage * code improvements
1 parent df0a424 commit 1e9ae76

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,13 @@ private void resizeVolume(VolumeInfo volumeInfo) {
12791279
}
12801280

12811281
org.apache.cloudstack.storage.datastore.api.Volume scaleIOVolume = client.getVolume(scaleIOVolumeId);
1282-
long newSizeInGB = newSizeInBytes / (1024 * 1024 * 1024);
1283-
long newSizeIn8gbBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0);
1282+
double newSizeInGB = newSizeInBytes / (1024.0 * 1024 * 1024);
1283+
long newSizeIn8GBBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0);
12841284

1285-
if (scaleIOVolume.getSizeInKb() == newSizeIn8gbBoundary << 20) {
1285+
if (scaleIOVolume.getSizeInKb() == newSizeIn8GBBoundary << 20) {
12861286
logger.debug("No resize necessary at API");
12871287
} else {
1288-
scaleIOVolume = client.resizeVolume(scaleIOVolumeId, (int) newSizeIn8gbBoundary);
1288+
scaleIOVolume = client.resizeVolume(scaleIOVolumeId, (int) newSizeIn8GBBoundary);
12891289
if (scaleIOVolume == null) {
12901290
throw new CloudRuntimeException("Failed to resize volume: " + volumeInfo.getName());
12911291
}
@@ -1411,15 +1411,12 @@ public void resize(DataObject dataObject, AsyncCompletionCallback<CreateCmdResul
14111411

14121412
@Override
14131413
public long getVolumeSizeRequiredOnPool(long volumeSize, Long templateSize, boolean isEncryptionRequired) {
1414-
if(volumeSize == 0) {
1415-
volumeSize = 8589934592L;
1416-
}
1417-
long newSizeInGB = volumeSize / (1024 * 1024 * 1024);
1414+
double newSizeInGB = volumeSize / (1024.0 * 1024 * 1024);
14181415
if (templateSize != null && isEncryptionRequired && needsExpansionForEncryptionHeader(templateSize, volumeSize)) {
1419-
newSizeInGB = (volumeSize + (1<<30)) / (1024 * 1024 * 1024);
1416+
newSizeInGB = (volumeSize + (1<<30)) / (1024.0 * 1024 * 1024);
14201417
}
1421-
long newSizeIn8gbBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0);
1422-
return newSizeIn8gbBoundary * (1024 * 1024 * 1024);
1418+
long newSizeIn8GBBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0);
1419+
return newSizeIn8GBBoundary * (1024 * 1024 * 1024);
14231420
}
14241421

14251422
@Override

plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,18 @@ public void testCopyOfflineVolumeFailureWhenNoEndpointFound() {
555555

556556
@Test
557557
public void testGetVolumeSizeRequiredOnPool() {
558+
Assert.assertEquals(8L * (1024 * 1024 * 1024),
559+
scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool(
560+
52428800,
561+
null,
562+
false));
563+
564+
Assert.assertEquals(8L * (1024 * 1024 * 1024),
565+
scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool(
566+
52428800,
567+
52428800L,
568+
true));
569+
558570
Assert.assertEquals(16L * (1024 * 1024 * 1024),
559571
scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool(
560572
10L * (1024 * 1024 * 1024),

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ private static boolean waitForDeviceSymlink(String devPath) {
150150
}
151151

152152
public static String getVolumeNameFromPath(final String volumeUuid, boolean tildeNeeded) {
153+
if (volumeUuid == null) {
154+
return null;
155+
}
153156
if (volumeUuid.startsWith("/dev/storpool/")) {
154157
return volumeUuid.split("/")[3];
155158
} else if (volumeUuid.startsWith("/dev/storpool-byid/")) {

0 commit comments

Comments
 (0)