Skip to content

Commit 4f9c349

Browse files
committed
Merge release branch 4.19 to 4.20
* 4.19: Restrict the migration of volumes attached to VMs in Starting state (#9725)
2 parents bd488c4 + 21416cd commit 4f9c349

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
@@ -3268,6 +3268,7 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
32683268
VMInstanceVO vm = null;
32693269
if (instanceId != null) {
32703270
vm = _vmInstanceDao.findById(instanceId);
3271+
checkVmStateForMigration(vm, vol);
32713272
}
32723273

32733274
// Check that Vm to which this volume is attached does not have VM Snapshots
@@ -3465,6 +3466,22 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
34653466
return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, newDiskOffering);
34663467
}
34673468

3469+
private void checkVmStateForMigration(VMInstanceVO vm, VolumeVO vol) {
3470+
List<State> suitableVmStatesForMigration = List.of(State.Stopped, State.Running, State.Shutdown);
3471+
3472+
if (!suitableVmStatesForMigration.contains(vm.getState())) {
3473+
s_logger.debug(String.format(
3474+
"Unable to migrate volume: [%s] Id: [%s] because the VM: [%s] Id: [%s] is in state [%s], which is not supported for migration.",
3475+
vol.getName(), vol.getId(), vm.getInstanceName(), vm.getUuid(), vm.getState()
3476+
));
3477+
3478+
throw new CloudRuntimeException(String.format(
3479+
"Volume migration is not allowed when the VM is in the %s state. Supported states are: %s.",
3480+
vm.getState(), suitableVmStatesForMigration
3481+
));
3482+
}
3483+
}
3484+
34683485
private boolean isSourceOrDestNotOnStorPool(StoragePoolVO storagePoolVO, StoragePoolVO destinationStoragePoolVo) {
34693486
return storagePoolVO.getPoolType() != Storage.StoragePoolType.StorPool
34703487
|| destinationStoragePoolVo.getPoolType() != Storage.StoragePoolType.StorPool;

0 commit comments

Comments
 (0)