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

pearl11594 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 f992ebb52a5 fix volume migration across cluster-scope pools (#10266)
f992ebb52a5 is described below

commit f992ebb52a5760bf7fe1714c162bada4de463ef8
Author: Wei Zhou <[email protected]>
AuthorDate: Thu Feb 27 14:50:22 2025 +0100

    fix volume migration across cluster-scope pools (#10266)
---
 .../java/com/cloud/storage/MigrationOptions.java     | 11 +++++++++--
 .../KvmNonManagedStorageDataMotionStrategy.java      |  2 +-
 .../motion/StorageSystemDataMotionStrategy.java      | 20 ++++++++++++++------
 .../kvm/resource/LibvirtComputingResource.java       |  4 ++++
 .../hypervisor/kvm/storage/KVMStorageProcessor.java  |  6 ++++++
 5 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/api/src/main/java/com/cloud/storage/MigrationOptions.java 
b/api/src/main/java/com/cloud/storage/MigrationOptions.java
index a39a2a7c827..8b642d09e29 100644
--- a/api/src/main/java/com/cloud/storage/MigrationOptions.java
+++ b/api/src/main/java/com/cloud/storage/MigrationOptions.java
@@ -24,6 +24,7 @@ public class MigrationOptions implements Serializable {
 
     private String srcPoolUuid;
     private Storage.StoragePoolType srcPoolType;
+    private Long srcPoolClusterId;
     private Type type;
     private ScopeType scopeType;
     private String srcBackingFilePath;
@@ -38,21 +39,23 @@ public class MigrationOptions implements Serializable {
     public MigrationOptions() {
     }
 
-    public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType 
srcPoolType, String srcBackingFilePath, boolean copySrcTemplate, ScopeType 
scopeType) {
+    public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType 
srcPoolType, String srcBackingFilePath, boolean copySrcTemplate, ScopeType 
scopeType, Long srcPoolClusterId) {
         this.srcPoolUuid = srcPoolUuid;
         this.srcPoolType = srcPoolType;
         this.type = Type.LinkedClone;
         this.scopeType = scopeType;
         this.srcBackingFilePath = srcBackingFilePath;
         this.copySrcTemplate = copySrcTemplate;
+        this.srcPoolClusterId = srcPoolClusterId;
     }
 
-    public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType 
srcPoolType, String srcVolumeUuid, ScopeType scopeType) {
+    public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType 
srcPoolType, String srcVolumeUuid, ScopeType scopeType, Long srcPoolClusterId) {
         this.srcPoolUuid = srcPoolUuid;
         this.srcPoolType = srcPoolType;
         this.type = Type.FullClone;
         this.scopeType = scopeType;
         this.srcVolumeUuid = srcVolumeUuid;
+        this.srcPoolClusterId = srcPoolClusterId;
     }
 
     public String getSrcPoolUuid() {
@@ -63,6 +66,10 @@ public class MigrationOptions implements Serializable {
         return srcPoolType;
     }
 
+    public Long getSrcPoolClusterId() {
+        return srcPoolClusterId;
+    }
+
     public ScopeType getScopeType() { return scopeType; }
 
     public String getSrcBackingFilePath() {
diff --git 
a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java
 
b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java
index f2ccce75690..7059b32f9b7 100644
--- 
a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java
+++ 
b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java
@@ -217,7 +217,7 @@ public class KvmNonManagedStorageDataMotionStrategy extends 
StorageSystemDataMot
         }
 
         VMTemplateStoragePoolVO sourceVolumeTemplateStoragePoolVO = 
vmTemplatePoolDao.findByPoolTemplate(destStoragePool.getId(), 
srcVolumeInfo.getTemplateId(), null);
-        if (sourceVolumeTemplateStoragePoolVO == null && 
(isStoragePoolTypeInList(destStoragePool.getPoolType(), 
StoragePoolType.Filesystem, StoragePoolType.SharedMountPoint))) {
+        if (sourceVolumeTemplateStoragePoolVO == null && 
(isStoragePoolTypeInList(destStoragePool.getPoolType(), 
StoragePoolType.NetworkFilesystem, StoragePoolType.Filesystem, 
StoragePoolType.SharedMountPoint))) {
             DataStore sourceTemplateDataStore = 
dataStoreManagerImpl.getRandomImageStore(srcVolumeInfo.getDataCenterId());
             if (sourceTemplateDataStore != null) {
                 TemplateInfo sourceTemplateInfo = 
templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), 
sourceTemplateDataStore);
diff --git 
a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
 
b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
index f2d54823a0c..9a5b0a197e1 100644
--- 
a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
+++ 
b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
@@ -1948,18 +1948,26 @@ public class StorageSystemDataMotionStrategy implements 
DataMotionStrategy {
     /**
      * Return expected MigrationOptions for a linked clone volume live storage 
migration
      */
-    protected MigrationOptions createLinkedCloneMigrationOptions(VolumeInfo 
srcVolumeInfo, VolumeInfo destVolumeInfo, String srcVolumeBackingFile, String 
srcPoolUuid, Storage.StoragePoolType srcPoolType) {
+    protected MigrationOptions createLinkedCloneMigrationOptions(VolumeInfo 
srcVolumeInfo, VolumeInfo destVolumeInfo, String srcVolumeBackingFile, 
StoragePoolVO srcPool) {
+        String srcPoolUuid = srcPool.getUuid();
+        Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
+        Long srcPoolClusterId = srcPool.getClusterId();
         VMTemplateStoragePoolVO ref = 
templatePoolDao.findByPoolTemplate(destVolumeInfo.getPoolId(), 
srcVolumeInfo.getTemplateId(), null);
         boolean updateBackingFileReference = ref == null;
         String backingFile = !updateBackingFileReference ? 
ref.getInstallPath() : srcVolumeBackingFile;
-        return new MigrationOptions(srcPoolUuid, srcPoolType, backingFile, 
updateBackingFileReference, 
srcVolumeInfo.getDataStore().getScope().getScopeType());
+        ScopeType scopeType = 
srcVolumeInfo.getDataStore().getScope().getScopeType();
+        return new MigrationOptions(srcPoolUuid, srcPoolType, backingFile, 
updateBackingFileReference, scopeType, srcPoolClusterId);
     }
 
     /**
      * Return expected MigrationOptions for a full clone volume live storage 
migration
      */
-    protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo 
srcVolumeInfo, VirtualMachineTO vmTO, Host srcHost, String srcPoolUuid, 
Storage.StoragePoolType srcPoolType) {
-        return new MigrationOptions(srcPoolUuid, srcPoolType, 
srcVolumeInfo.getPath(), 
srcVolumeInfo.getDataStore().getScope().getScopeType());
+    protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo 
srcVolumeInfo, VirtualMachineTO vmTO, Host srcHost, StoragePoolVO srcPool) {
+        String srcPoolUuid = srcPool.getUuid();
+        Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
+        Long srcPoolClusterId = srcPool.getClusterId();
+        ScopeType scopeType = 
srcVolumeInfo.getDataStore().getScope().getScopeType();
+        return new MigrationOptions(srcPoolUuid, srcPoolType, 
srcVolumeInfo.getPath(), scopeType, srcPoolClusterId);
     }
 
     /**
@@ -1982,9 +1990,9 @@ public class StorageSystemDataMotionStrategy implements 
DataMotionStrategy {
 
         MigrationOptions migrationOptions;
         if (MigrationOptions.Type.LinkedClone.equals(migrationType)) {
-            migrationOptions = 
createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, 
srcVolumeBackingFile, srcPoolUuid, srcPoolType);
+            migrationOptions = 
createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, 
srcVolumeBackingFile, srcPool);
         } else {
-            migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, 
vmTO, srcHost, srcPoolUuid, srcPoolType);
+            migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, 
vmTO, srcHost, srcPool);
         }
         
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
         destVolumeInfo.setMigrationOptions(migrationOptions);
diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 973f053fee6..b43c7dced0d 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -625,6 +625,10 @@ public class LibvirtComputingResource extends 
ServerResourceBase implements Serv
         return libvirtUtilitiesHelper;
     }
 
+    public String getClusterId() {
+        return clusterId;
+    }
+
     public CPUStat getCPUStat() {
         return cpuStat;
     }
diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index 193a3287361..c76111c7c9c 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -2638,6 +2638,12 @@ public class KVMStorageProcessor implements 
StorageProcessor {
             return localPool;
         }
 
+        if (migrationOptions.getScopeType().equals(ScopeType.CLUSTER)
+                && migrationOptions.getSrcPoolClusterId() != null
+                && 
!migrationOptions.getSrcPoolClusterId().toString().equals(resource.getClusterId()))
 {
+            return localPool;
+        }
+
         return 
storagePoolMgr.getStoragePool(migrationOptions.getSrcPoolType(), 
migrationOptions.getSrcPoolUuid());
     }
 }

Reply via email to