diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java index bcbdc2244b1b..66cd6a8f0ff5 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java @@ -428,6 +428,19 @@ private String createResource(VolumeInfo vol, StoragePoolVO storagePoolVO) } } + private void resizeResource(DevelopersApi api, String resourceName, long sizeByte) throws ApiException { + VolumeDefinitionModify dfm = new VolumeDefinitionModify(); + dfm.setSizeKib(sizeByte / 1024); + + ApiCallRcList answers = api.volumeDefinitionModify(resourceName, 0, dfm); + if (answers.hasError()) { + s_logger.error("Resize error: " + answers.get(0).getMessage()); + throw new CloudRuntimeException(answers.get(0).getMessage()); + } else { + s_logger.info(String.format("Successfully resized %s to %d kib", resourceName, dfm.getSizeKib())); + } + } + private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolVO storagePoolVO) { // get the cached template on this storage VMTemplateStoragePoolVO tmplPoolRef = _vmTemplatePoolDao.findByPoolTemplate( @@ -452,6 +465,9 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV } s_logger.info("Clone resource definition " + cloneRes + " to " + rscName + " finished"); + + resizeResource(linstorApi, rscName, volumeInfo.getSize()); + applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName()); applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops()); @@ -738,26 +754,16 @@ public void resize(DataObject data, AsyncCompletionCallback cal dfm.setSizeKib(resizeParameter.newSize / 1024); try { + resizeResource(api, rscName, resizeParameter.newSize); + applyQoSSettings(pool, api, rscName, resizeParameter.newMaxIops); { final VolumeVO volume = _volumeDao.findById(vol.getId()); volume.setMinIops(resizeParameter.newMinIops); volume.setMaxIops(resizeParameter.newMaxIops); + volume.setSize(resizeParameter.newSize); _volumeDao.update(volume.getId(), volume); } - - ApiCallRcList answers = api.volumeDefinitionModify(rscName, 0, dfm); - if (answers.hasError()) - { - s_logger.error("Resize error: " + answers.get(0).getMessage()); - errMsg = answers.get(0).getMessage(); - } else - { - s_logger.info(String.format("Successfully resized %s to %d kib", rscName, dfm.getSizeKib())); - vol.setSize(resizeParameter.newSize); - vol.update(); - } - } catch (ApiException apiExc) { s_logger.error(apiExc); @@ -765,12 +771,10 @@ public void resize(DataObject data, AsyncCompletionCallback cal } CreateCmdResult result; - if (errMsg != null) - { + if (errMsg != null) { result = new CreateCmdResult(null, new Answer(null, false, errMsg)); result.setResult(errMsg); - } else - { + } else { // notify guests result = notifyResize(vol, oldSize, resizeParameter); }