Skip to content

Commit e1631ac

Browse files
weizhouapachedhslove
authored andcommitted
fix volume migration across cluster-scope pools (apache#10266)
1 parent 9b54184 commit e1631ac

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

api/src/main/java/com/cloud/storage/MigrationOptions.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class MigrationOptions implements Serializable {
2424

2525
private String srcPoolUuid;
2626
private Storage.StoragePoolType srcPoolType;
27+
private Long srcPoolClusterId;
2728
private Type type;
2829
private ScopeType scopeType;
2930
private String srcBackingFilePath;
@@ -38,21 +39,23 @@ public enum Type {
3839
public MigrationOptions() {
3940
}
4041

41-
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcBackingFilePath, boolean copySrcTemplate, ScopeType scopeType) {
42+
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcBackingFilePath, boolean copySrcTemplate, ScopeType scopeType, Long srcPoolClusterId) {
4243
this.srcPoolUuid = srcPoolUuid;
4344
this.srcPoolType = srcPoolType;
4445
this.type = Type.LinkedClone;
4546
this.scopeType = scopeType;
4647
this.srcBackingFilePath = srcBackingFilePath;
4748
this.copySrcTemplate = copySrcTemplate;
49+
this.srcPoolClusterId = srcPoolClusterId;
4850
}
4951

50-
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcVolumeUuid, ScopeType scopeType) {
52+
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcVolumeUuid, ScopeType scopeType, Long srcPoolClusterId) {
5153
this.srcPoolUuid = srcPoolUuid;
5254
this.srcPoolType = srcPoolType;
5355
this.type = Type.FullClone;
5456
this.scopeType = scopeType;
5557
this.srcVolumeUuid = srcVolumeUuid;
58+
this.srcPoolClusterId = srcPoolClusterId;
5659
}
5760

5861
public String getSrcPoolUuid() {
@@ -63,6 +66,10 @@ public Storage.StoragePoolType getSrcPoolType() {
6366
return srcPoolType;
6467
}
6568

69+
public Long getSrcPoolClusterId() {
70+
return srcPoolClusterId;
71+
}
72+
6673
public ScopeType getScopeType() { return scopeType; }
6774

6875
public String getSrcBackingFilePath() {

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ protected void copyTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo srcVolum
215215
}
216216

217217
VMTemplateStoragePoolVO sourceVolumeTemplateStoragePoolVO = vmTemplatePoolDao.findByPoolTemplate(destStoragePool.getId(), srcVolumeInfo.getTemplateId(), null);
218-
if (sourceVolumeTemplateStoragePoolVO == null && (isStoragePoolTypeInList(destStoragePool.getPoolType(), StoragePoolType.Filesystem, StoragePoolType.SharedMountPoint))) {
218+
if (sourceVolumeTemplateStoragePoolVO == null && (isStoragePoolTypeInList(destStoragePool.getPoolType(), StoragePoolType.NetworkFilesystem, StoragePoolType.Filesystem, StoragePoolType.SharedMountPoint))) {
219219
DataStore sourceTemplateDataStore = dataStoreManagerImpl.getRandomImageStore(srcVolumeInfo.getDataCenterId());
220220
if (sourceTemplateDataStore != null) {
221221
TemplateInfo sourceTemplateInfo = templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), sourceTemplateDataStore);

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,18 +1945,26 @@ private SnapshotDetailsVO handleSnapshotDetails(long csSnapshotId, String value)
19451945
/**
19461946
* Return expected MigrationOptions for a linked clone volume live storage migration
19471947
*/
1948-
protected MigrationOptions createLinkedCloneMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, String srcVolumeBackingFile, String srcPoolUuid, Storage.StoragePoolType srcPoolType) {
1948+
protected MigrationOptions createLinkedCloneMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, String srcVolumeBackingFile, StoragePoolVO srcPool) {
1949+
String srcPoolUuid = srcPool.getUuid();
1950+
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
1951+
Long srcPoolClusterId = srcPool.getClusterId();
19491952
VMTemplateStoragePoolVO ref = templatePoolDao.findByPoolTemplate(destVolumeInfo.getPoolId(), srcVolumeInfo.getTemplateId(), null);
19501953
boolean updateBackingFileReference = ref == null;
19511954
String backingFile = !updateBackingFileReference ? ref.getInstallPath() : srcVolumeBackingFile;
1952-
return new MigrationOptions(srcPoolUuid, srcPoolType, backingFile, updateBackingFileReference, srcVolumeInfo.getDataStore().getScope().getScopeType());
1955+
ScopeType scopeType = srcVolumeInfo.getDataStore().getScope().getScopeType();
1956+
return new MigrationOptions(srcPoolUuid, srcPoolType, backingFile, updateBackingFileReference, scopeType, srcPoolClusterId);
19531957
}
19541958

19551959
/**
19561960
* Return expected MigrationOptions for a full clone volume live storage migration
19571961
*/
1958-
protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeInfo, VirtualMachineTO vmTO, Host srcHost, String srcPoolUuid, Storage.StoragePoolType srcPoolType) {
1959-
return new MigrationOptions(srcPoolUuid, srcPoolType, srcVolumeInfo.getPath(), srcVolumeInfo.getDataStore().getScope().getScopeType());
1962+
protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeInfo, VirtualMachineTO vmTO, Host srcHost, StoragePoolVO srcPool) {
1963+
String srcPoolUuid = srcPool.getUuid();
1964+
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
1965+
Long srcPoolClusterId = srcPool.getClusterId();
1966+
ScopeType scopeType = srcVolumeInfo.getDataStore().getScope().getScopeType();
1967+
return new MigrationOptions(srcPoolUuid, srcPoolType, srcVolumeInfo.getPath(), scopeType, srcPoolClusterId);
19601968
}
19611969

19621970
/**
@@ -1979,9 +1987,9 @@ protected void setVolumeMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo de
19791987

19801988
MigrationOptions migrationOptions;
19811989
if (MigrationOptions.Type.LinkedClone.equals(migrationType)) {
1982-
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPoolUuid, srcPoolType);
1990+
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPool);
19831991
} else {
1984-
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
1992+
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPool);
19851993
}
19861994
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
19871995
destVolumeInfo.setMigrationOptions(migrationOptions);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ public LibvirtUtilitiesHelper getLibvirtUtilitiesHelper() {
673673
return libvirtUtilitiesHelper;
674674
}
675675

676+
public String getClusterId() {
677+
return clusterId;
678+
}
679+
676680
public CPUStat getCPUStat() {
677681
return cpuStat;
678682
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,6 +2862,12 @@ public KVMStoragePool getTemplateSourcePoolUsingMigrationOptions(KVMStoragePool
28622862
return localPool;
28632863
}
28642864

2865+
if (migrationOptions.getScopeType().equals(ScopeType.CLUSTER)
2866+
&& migrationOptions.getSrcPoolClusterId() != null
2867+
&& !migrationOptions.getSrcPoolClusterId().toString().equals(resource.getClusterId())) {
2868+
return localPool;
2869+
}
2870+
28652871
return storagePoolMgr.getStoragePool(migrationOptions.getSrcPoolType(), migrationOptions.getSrcPoolUuid());
28662872
}
28672873
}

0 commit comments

Comments
 (0)