This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.19 by this push:
     new 21416cd4034 Restrict the migration of volumes attached to VMs in 
Starting state (#9725)
21416cd4034 is described below

commit 21416cd40347836444411561633a6ce33a96c798
Author: Felipe <[email protected]>
AuthorDate: Wed Jan 8 04:49:21 2025 -0300

    Restrict the migration of volumes attached to VMs in Starting state (#9725)
    
    Co-authored-by: Bernardo De Marco Gonçalves <[email protected]>
---
 .../java/com/cloud/storage/VolumeApiServiceImpl.java    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index b506858b237..7f867eb01a9 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -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;

Reply via email to