Skip to content

Commit 1f1eda9

Browse files
committed
fix volume migration across cluster-scope pools
1 parent 2aa2e92 commit 1f1eda9

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
@@ -217,7 +217,7 @@ protected void copyTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo srcVolum
217217
}
218218

219219
VMTemplateStoragePoolVO sourceVolumeTemplateStoragePoolVO = vmTemplatePoolDao.findByPoolTemplate(destStoragePool.getId(), srcVolumeInfo.getTemplateId(), null);
220-
if (sourceVolumeTemplateStoragePoolVO == null && (isStoragePoolTypeInList(destStoragePool.getPoolType(), StoragePoolType.Filesystem, StoragePoolType.SharedMountPoint))) {
220+
if (sourceVolumeTemplateStoragePoolVO == null && (isStoragePoolTypeInList(destStoragePool.getPoolType(), StoragePoolType.NetworkFilesystem, StoragePoolType.Filesystem, StoragePoolType.SharedMountPoint))) {
221221
DataStore sourceTemplateDataStore = dataStoreManagerImpl.getRandomImageStore(srcVolumeInfo.getDataCenterId());
222222
if (sourceTemplateDataStore != null) {
223223
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
@@ -1937,18 +1937,26 @@ private SnapshotDetailsVO handleSnapshotDetails(long csSnapshotId, String value)
19371937
/**
19381938
* Return expected MigrationOptions for a linked clone volume live storage migration
19391939
*/
1940-
protected MigrationOptions createLinkedCloneMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, String srcVolumeBackingFile, String srcPoolUuid, Storage.StoragePoolType srcPoolType) {
1940+
protected MigrationOptions createLinkedCloneMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, String srcVolumeBackingFile, StoragePoolVO srcPool) {
1941+
String srcPoolUuid = srcPool.getUuid();
1942+
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
1943+
Long srcPoolClusterId = srcPool.getClusterId();
19411944
VMTemplateStoragePoolVO ref = templatePoolDao.findByPoolTemplate(destVolumeInfo.getPoolId(), srcVolumeInfo.getTemplateId(), null);
19421945
boolean updateBackingFileReference = ref == null;
19431946
String backingFile = !updateBackingFileReference ? ref.getInstallPath() : srcVolumeBackingFile;
1944-
return new MigrationOptions(srcPoolUuid, srcPoolType, backingFile, updateBackingFileReference, srcVolumeInfo.getDataStore().getScope().getScopeType());
1947+
ScopeType scopeType = srcVolumeInfo.getDataStore().getScope().getScopeType();
1948+
return new MigrationOptions(srcPoolUuid, srcPoolType, backingFile, updateBackingFileReference, scopeType, srcPoolClusterId);
19451949
}
19461950

19471951
/**
19481952
* Return expected MigrationOptions for a full clone volume live storage migration
19491953
*/
1950-
protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeInfo, VirtualMachineTO vmTO, Host srcHost, String srcPoolUuid, Storage.StoragePoolType srcPoolType) {
1951-
return new MigrationOptions(srcPoolUuid, srcPoolType, srcVolumeInfo.getPath(), srcVolumeInfo.getDataStore().getScope().getScopeType());
1954+
protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeInfo, VirtualMachineTO vmTO, Host srcHost, StoragePoolVO srcPool) {
1955+
String srcPoolUuid = srcPool.getUuid();
1956+
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
1957+
Long srcPoolClusterId = srcPool.getClusterId();
1958+
ScopeType scopeType = srcVolumeInfo.getDataStore().getScope().getScopeType();
1959+
return new MigrationOptions(srcPoolUuid, srcPoolType, srcVolumeInfo.getPath(), scopeType, srcPoolClusterId);
19521960
}
19531961

19541962
/**
@@ -1971,9 +1979,9 @@ protected void setVolumeMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo de
19711979

19721980
MigrationOptions migrationOptions;
19731981
if (MigrationOptions.Type.LinkedClone.equals(migrationType)) {
1974-
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPoolUuid, srcPoolType);
1982+
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPool);
19751983
} else {
1976-
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
1984+
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPool);
19771985
}
19781986
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
19791987
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
@@ -625,6 +625,10 @@ public LibvirtUtilitiesHelper getLibvirtUtilitiesHelper() {
625625
return libvirtUtilitiesHelper;
626626
}
627627

628+
public String getClusterId() {
629+
return clusterId;
630+
}
631+
628632
public CPUStat getCPUStat() {
629633
return cpuStat;
630634
}

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
@@ -2620,6 +2620,12 @@ public KVMStoragePool getTemplateSourcePoolUsingMigrationOptions(KVMStoragePool
26202620
return localPool;
26212621
}
26222622

2623+
if (migrationOptions.getScopeType().equals(ScopeType.CLUSTER)
2624+
&& migrationOptions.getSrcPoolClusterId() != null
2625+
&& !migrationOptions.getSrcPoolClusterId().toString().equals(resource.getClusterId())) {
2626+
return localPool;
2627+
}
2628+
26232629
return storagePoolMgr.getStoragePool(migrationOptions.getSrcPoolType(), migrationOptions.getSrcPoolUuid());
26242630
}
26252631
}

0 commit comments

Comments
 (0)