Skip to content

Commit

Permalink
linstor: resize root disk on offerings with different size
Browse files Browse the repository at this point in the history
  • Loading branch information
rp- committed Sep 11, 2023
1 parent f049f54 commit ba44a93
Showing 1 changed file with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -452,6 +465,11 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV
}

s_logger.info("Clone resource definition " + cloneRes + " to " + rscName + " finished");

if (volumeInfo.getSize() != null && volumeInfo.getSize() > 0) {
resizeResource(linstorApi, rscName, volumeInfo.getSize());
}

applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops());

Expand Down Expand Up @@ -738,39 +756,27 @@ public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> 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);
errMsg = apiExc.getBestMessage();
}

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);
}
Expand Down

0 comments on commit ba44a93

Please sign in to comment.