Skip to content

Commit 21416cd

Browse files
Restrict the migration of volumes attached to VMs in Starting state (#9725)
Co-authored-by: Bernardo De Marco Gonçalves <[email protected]>
1 parent d8c321d commit 21416cd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,6 +3201,7 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
32013201
VMInstanceVO vm = null;
32023202
if (instanceId != null) {
32033203
vm = _vmInstanceDao.findById(instanceId);
3204+
checkVmStateForMigration(vm, vol);
32043205
}
32053206

32063207
// Check that Vm to which this volume is attached does not have VM Snapshots
@@ -3398,6 +3399,22 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
33983399
return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, newDiskOffering);
33993400
}
34003401

3402+
private void checkVmStateForMigration(VMInstanceVO vm, VolumeVO vol) {
3403+
List<State> suitableVmStatesForMigration = List.of(State.Stopped, State.Running, State.Shutdown);
3404+
3405+
if (!suitableVmStatesForMigration.contains(vm.getState())) {
3406+
s_logger.debug(String.format(
3407+
"Unable to migrate volume: [%s] Id: [%s] because the VM: [%s] Id: [%s] is in state [%s], which is not supported for migration.",
3408+
vol.getName(), vol.getId(), vm.getInstanceName(), vm.getUuid(), vm.getState()
3409+
));
3410+
3411+
throw new CloudRuntimeException(String.format(
3412+
"Volume migration is not allowed when the VM is in the %s state. Supported states are: %s.",
3413+
vm.getState(), suitableVmStatesForMigration
3414+
));
3415+
}
3416+
}
3417+
34013418
private boolean isSourceOrDestNotOnStorPool(StoragePoolVO storagePoolVO, StoragePoolVO destinationStoragePoolVo) {
34023419
return storagePoolVO.getPoolType() != Storage.StoragePoolType.StorPool
34033420
|| destinationStoragePoolVo.getPoolType() != Storage.StoragePoolType.StorPool;

0 commit comments

Comments
 (0)