sureshanaparti commented on code in PR #8755:
URL: https://github.com/apache/cloudstack/pull/8755#discussion_r1516082981
##########
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java:
##########
@@ -328,66 +373,107 @@ private StorPoolSetVolumeEncryptionAnswer
createEncryptedVolume(DataStore dataSt
public void resize(DataObject data,
AsyncCompletionCallback<CreateCmdResult> callback) {
String path = null;
String err = null;
- ResizeVolumeAnswer answer = null;
if (data.getType() == DataObjectType.VOLUME) {
VolumeObject vol = (VolumeObject)data;
- StoragePool pool = (StoragePool)data.getDataStore();
- ResizeVolumePayload payload =
(ResizeVolumePayload)vol.getpayload();
+ path = vol.getPath();
- final String name =
StorPoolStorageAdaptor.getVolumeNameFromPath(vol.getPath(), true);
- final long oldSize = vol.getSize();
- Long oldMaxIops = vol.getMaxIops();
+ err = resizeVolume(data, path, err, vol);
+ } else {
+ err = String.format("Invalid object type \"%s\" passed to
resize", data.getType());
+ }
- try {
- SpConnectionDesc conn =
StorPoolUtil.getSpConnection(data.getDataStore().getUuid(),
data.getDataStore().getId(), storagePoolDetailsDao, primaryStoreDao);
+ CreateCmdResult res = new CreateCmdResult(path, new Answer(null, err
!= null, err));
+ res.setResult(err);
+ callback.complete(res);
+ }
- long maxIops = payload.newMaxIops == null ? Long.valueOf(0) :
payload.newMaxIops;
+ private String resizeVolume(DataObject data, String path, String err,
VolumeObject vol) {
+ ResizeVolumePayload payload = (ResizeVolumePayload)vol.getpayload();
+ boolean needResize = vol.getSize() != payload.newSize;
- StorPoolUtil.spLog("StorpoolPrimaryDataStoreDriverImpl.resize:
name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s", name,
vol.getUuid(), oldSize, payload.newSize, payload.shrinkOk, maxIops);
+ final String name = StorPoolStorageAdaptor.getVolumeNameFromPath(path,
true);
+ final long oldSize = vol.getSize();
+ Long oldMaxIops = vol.getMaxIops();
- SpApiResponse resp = StorPoolUtil.volumeUpdate(name,
payload.newSize, payload.shrinkOk, maxIops, conn);
- if (resp.getError() != null) {
- err = String.format("Could not resize StorPool volume %s.
Error: %s", name, resp.getError());
- } else {
- StorPoolResizeVolumeCommand resizeCmd = new
StorPoolResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool),
vol.getSize(), payload.newSize, payload.shrinkOk,
- payload.instanceName, payload.hosts == null ?
false : true);
- answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool,
payload.hosts, resizeCmd);
+ try {
+ SpConnectionDesc conn =
StorPoolUtil.getSpConnection(data.getDataStore().getUuid(),
data.getDataStore().getId(), storagePoolDetailsDao, primaryStoreDao);
- if (answer == null || !answer.getResult()) {
- err = answer != null ? answer.getDetails() : "return a
null answer, resize failed for unknown reason";
- } else {
- path =
StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false));
-
- vol.setSize(payload.newSize);
- vol.update();
- if (payload.newMaxIops != null) {
- VolumeVO volume = volumeDao.findById(vol.getId());
- volume.setMaxIops(payload.newMaxIops);
- volumeDao.update(volume.getId(), volume);
- }
+ err = updateStorPoolVolume(err, vol, payload, conn);
+ if (err == null && needResize) {
+ err = notifyQemuForTheNewSize(data, err, vol, payload);
+ }
- updateStoragePool(vol.getPoolId(), payload.newSize -
oldSize);
- }
+ if (err != null) {
+ // try restoring volume to its initial size
+ SpApiResponse response = StorPoolUtil.volumeUpdate(name,
oldSize, true, oldMaxIops, conn);
+ if (response.getError() != null) {
+ logger.debug(String.format("Could not resize StorPool
volume %s back to its original size. Error: %s", name, response.getError()));
}
- if (err != null) {
- // try restoring volume to its initial size
- resp = StorPoolUtil.volumeUpdate(name, oldSize, true,
oldMaxIops, conn);
- if (resp.getError() != null) {
- logger.debug(String.format("Could not resize StorPool
volume %s back to its original size. Error: %s", name, resp.getError()));
- }
- }
- } catch (Exception e) {
- logger.debug("sending resize command failed", e);
- err = e.toString();
}
+ } catch (Exception e) {
+ logger.debug("sending resize command failed", e);
+ err = e.toString();
+ }
+ return err;
+ }
+
+ private String notifyQemuForTheNewSize(DataObject data, String err,
VolumeObject vol, ResizeVolumePayload payload)
Review Comment:
```suggestion
private String notifyQemuForTheNewSize(DataObject data, VolumeObject
vol, ResizeVolumePayload payload)
```
seems `err` not needed in the call
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]