Restrict the migration of volumes attached to VMs in Starting state (#9725)

Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
This commit is contained in:
Felipe 2025-01-08 04:49:21 -03:00 committed by GitHub
parent d8c321d57a
commit 21416cd403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 0 deletions

View File

@ -3201,6 +3201,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
VMInstanceVO vm = null;
if (instanceId != null) {
vm = _vmInstanceDao.findById(instanceId);
checkVmStateForMigration(vm, vol);
}
// Check that Vm to which this volume is attached does not have VM Snapshots
@ -3398,6 +3399,22 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, newDiskOffering);
}
private void checkVmStateForMigration(VMInstanceVO vm, VolumeVO vol) {
List<State> suitableVmStatesForMigration = List.of(State.Stopped, State.Running, State.Shutdown);
if (!suitableVmStatesForMigration.contains(vm.getState())) {
s_logger.debug(String.format(
"Unable to migrate volume: [%s] Id: [%s] because the VM: [%s] Id: [%s] is in state [%s], which is not supported for migration.",
vol.getName(), vol.getId(), vm.getInstanceName(), vm.getUuid(), vm.getState()
));
throw new CloudRuntimeException(String.format(
"Volume migration is not allowed when the VM is in the %s state. Supported states are: %s.",
vm.getState(), suitableVmStatesForMigration
));
}
}
private boolean isSourceOrDestNotOnStorPool(StoragePoolVO storagePoolVO, StoragePoolVO destinationStoragePoolVo) {
return storagePoolVO.getPoolType() != Storage.StoragePoolType.StorPool
|| destinationStoragePoolVo.getPoolType() != Storage.StoragePoolType.StorPool;