Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvm: fix volume migration across cluster-scope pools #10266

Draft
wants to merge 1 commit into
base: 4.19
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions api/src/main/java/com/cloud/storage/MigrationOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

private String srcPoolUuid;
private Storage.StoragePoolType srcPoolType;
private Long srcPoolClusterId;
private Type type;
private ScopeType scopeType;
private String srcBackingFilePath;
Expand All @@ -38,21 +39,23 @@
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) {

Check warning on line 42 in api/src/main/java/com/cloud/storage/MigrationOptions.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L42 was not covered by tests
this.srcPoolUuid = srcPoolUuid;
this.srcPoolType = srcPoolType;
this.type = Type.LinkedClone;
this.scopeType = scopeType;
this.srcBackingFilePath = srcBackingFilePath;
this.copySrcTemplate = copySrcTemplate;
this.srcPoolClusterId = srcPoolClusterId;

Check warning on line 49 in api/src/main/java/com/cloud/storage/MigrationOptions.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L49 was not covered by tests
}

public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcVolumeUuid, ScopeType scopeType) {
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcVolumeUuid, ScopeType scopeType, Long srcPoolClusterId) {

Check warning on line 52 in api/src/main/java/com/cloud/storage/MigrationOptions.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L52 was not covered by tests
this.srcPoolUuid = srcPoolUuid;
this.srcPoolType = srcPoolType;
this.type = Type.FullClone;
this.scopeType = scopeType;
this.srcVolumeUuid = srcVolumeUuid;
this.srcPoolClusterId = srcPoolClusterId;

Check warning on line 58 in api/src/main/java/com/cloud/storage/MigrationOptions.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L58 was not covered by tests
}

public String getSrcPoolUuid() {
Expand All @@ -63,6 +66,10 @@
return srcPoolType;
}

public Long getSrcPoolClusterId() {
return srcPoolClusterId;
}

Check warning on line 71 in api/src/main/java/com/cloud/storage/MigrationOptions.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/com/cloud/storage/MigrationOptions.java#L69-L71

Added lines #L69 - L71 were not covered by tests

public ScopeType getScopeType() { return scopeType; }

public String getSrcBackingFilePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected void copyTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo srcVolum
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1937,18 +1937,26 @@
/**
* 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();

Check warning on line 1943 in engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java#L1940-L1943

Added lines #L1940 - L1943 were not covered by tests
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);

Check warning on line 1948 in engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java#L1947-L1948

Added lines #L1947 - L1948 were not covered by tests
}

/**
* 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);

Check warning on line 1959 in engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java#L1954-L1959

Added lines #L1954 - L1959 were not covered by tests
}

/**
Expand All @@ -1971,9 +1979,9 @@

MigrationOptions migrationOptions;
if (MigrationOptions.Type.LinkedClone.equals(migrationType)) {
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPoolUuid, srcPoolType);
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPool);

Check warning on line 1982 in engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1982 was not covered by tests
} else {
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPool);

Check warning on line 1984 in engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1984 was not covered by tests
}
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
destVolumeInfo.setMigrationOptions(migrationOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@
return libvirtUtilitiesHelper;
}

public String getClusterId() {
return clusterId;
}

Check warning on line 630 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java#L628-L630

Added lines #L628 - L630 were not covered by tests

public CPUStat getCPUStat() {
return cpuStat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2620,6 +2620,12 @@
return localPool;
}

if (migrationOptions.getScopeType().equals(ScopeType.CLUSTER)
&& migrationOptions.getSrcPoolClusterId() != null
&& !migrationOptions.getSrcPoolClusterId().toString().equals(resource.getClusterId())) {
return localPool;

Check warning on line 2626 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2626 was not covered by tests
}

return storagePoolMgr.getStoragePool(migrationOptions.getSrcPoolType(), migrationOptions.getSrcPoolUuid());
}
}