Copilot commented on code in PR #14698:
URL: https://github.com/apache/cloudstack/pull/14698#discussion_r4663296912
##########
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java:
##########
@@ -384,14 +388,28 @@ private StorPoolSetVolumeEncryptionAnswer
createEncryptedVolume(DataStore dataSt
ans = new StorPoolSetVolumeEncryptionAnswer(null, false, "Could
not find a host with volume encryption");
} else {
StorPoolSetVolumeEncryptionCommand cmd = new
StorPoolSetVolumeEncryptionCommand(volume, parentName, isDataDisk);
- ans = (StorPoolSetVolumeEncryptionAnswer) ep.sendMessage(cmd);
- if (ans.getResult()) {
- updateStoragePool(dataStore.getId(), size);
+ Answer answer = ep.sendMessage(cmd);
+ if (answer instanceof StorPoolSetVolumeEncryptionAnswer) {
+ ans = (StorPoolSetVolumeEncryptionAnswer) answer;
+ } else {
+ ans = new StorPoolSetVolumeEncryptionAnswer(cmd, false, answer
!= null ? answer.getDetails() : "Could not encrypt the volume, a null answer
was returned");
Review Comment:
When a generic answer has null details, this branch creates a failed
encryption answer with no error text and deletes the backend volume. Since
`createAsync` and `copyAsync` use that text to mark callback failure, they
instead report success for the deleted volume. Supply a non-null fallback error
when the generic answer has no details.
##########
plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolSetVolumeEncryptionCommandWrapper.java:
##########
@@ -83,13 +84,16 @@ public StorPoolSetVolumeEncryptionAnswer
execute(StorPoolSetVolumeEncryptionComm
private KVMPhysicalDisk encryptRootDisk(StorPoolSetVolumeEncryptionCommand
command, VolumeObjectTO volume,
String srcVolumeName, KVMStoragePool pool, KVMPhysicalDisk disk) {
StorPoolStorageAdaptor.attachOrDetachVolume("attach", "snapshot",
srcVolumeName);
- KVMPhysicalDisk srcVolume = pool.getPhysicalDisk(srcVolumeName);
- disk = copyPhysicalDisk(srcVolume, disk, command.getWait() * 1000,
null, volume.getPassphrase());
- disk.setQemuEncryptFormat(QemuObject.EncryptFormat.LUKS);
- disk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
- volume.setEncryptFormat(disk.getQemuEncryptFormat().toString());
- StorPoolStorageAdaptor.attachOrDetachVolume("detach", "snapshot",
srcVolumeName);
- return disk;
+ try {
+ KVMPhysicalDisk srcVolume = pool.getPhysicalDisk(srcVolumeName);
+ disk = copyPhysicalDisk(srcVolume, disk, command.getWait() * 1000,
null, volume.getPassphrase());
+ disk.setQemuEncryptFormat(QemuObject.EncryptFormat.LUKS);
+ disk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
+ volume.setEncryptFormat(disk.getQemuEncryptFormat().toString());
+ return disk;
+ } finally {
+ StorPoolStorageAdaptor.attachOrDetachVolume("detach", "snapshot",
srcVolumeName);
+ }
Review Comment:
If ROOT disk copying or encryption fails and snapshot detachment also
throws, this `finally` block replaces the original error with the detach error.
The returned failure answer therefore loses the encryption failure that this PR
intends to preserve. Keep the original exception and attach the cleanup error
as a suppressed exception; a detach-only failure can retain its existing
behavior.
##########
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java:
##########
@@ -444,23 +462,29 @@ private String resizeVolume(DataObject data, String path,
VolumeObject vol) {
}
private void updateVolumeWithTheNewSize(VolumeObject vol,
ResizeVolumePayload payload) {
+ long oldSize = vol.getSize();
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);
}
- updateStoragePool(vol.getPoolId(), payload.newSize - vol.getSize());
+ updateStoragePool(vol.getPoolId(), payload.newSize - oldSize);
}
- private String notifyQemuForTheNewSize(DataObject data, String err,
VolumeObject vol, ResizeVolumePayload payload)
- throws StorageUnavailableException {
+ private String notifyQemuForTheNewSize(DataObject data, String err,
VolumeObject vol, ResizeVolumePayload payload) {
StoragePool pool = (StoragePool)data.getDataStore();
StorPoolResizeVolumeCommand resizeCmd = new
StorPoolResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool),
vol.getSize(), payload.newSize, payload.shrinkOk,
payload.instanceName, payload.hosts == null ? false : true);
- ResizeVolumeAnswer answer = (ResizeVolumeAnswer)
storageMgr.sendToPool(pool, payload.hosts, resizeCmd);
+ // any failure is returned as an error, so the StorPool volume is
restored to its initial size
+ Answer answer;
+ try {
+ answer = storageMgr.sendToPool(pool, payload.hosts, resizeCmd);
+ } catch (Exception e) {
+ return String.format("Could not send the resize command for volume
[%s] due to: %s", vol.getPath(), e.getMessage());
+ }
if (answer == null || !answer.getResult()) {
err = answer != null ? answer.getDetails() : "return a null
answer, resize failed for unknown reason";
Review Comment:
If the newly accepted generic answer has `result=false` and null details,
`notifyQemuForTheNewSize` returns null. The resize then skips rollback, updates
the recorded size and pool usage, and reports success despite the agent
failure. Ensure every failed answer produces a non-null error string.
##########
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java:
##########
@@ -384,14 +388,28 @@ private StorPoolSetVolumeEncryptionAnswer
createEncryptedVolume(DataStore dataSt
ans = new StorPoolSetVolumeEncryptionAnswer(null, false, "Could
not find a host with volume encryption");
} else {
StorPoolSetVolumeEncryptionCommand cmd = new
StorPoolSetVolumeEncryptionCommand(volume, parentName, isDataDisk);
- ans = (StorPoolSetVolumeEncryptionAnswer) ep.sendMessage(cmd);
- if (ans.getResult()) {
- updateStoragePool(dataStore.getId(), size);
+ Answer answer = ep.sendMessage(cmd);
Review Comment:
`RemoteHostEndPoint.sendMessage` throws on agent unavailability or timeout,
bypassing the new failed-encryption cleanup. The create/copy operation reports
failure but leaves the newly allocated StorPool volume behind. Handle delivery
exceptions with cleanup or reconciliation; after a timeout, establish the
remote outcome before force-deleting a device that may still be undergoing
encryption.
--
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]