Skip to content

Commit a7b9a41

Browse files
author
Pearl Dsilva
committed
CLVM: Fix volume mapping and disk path matching for storage migration
1 parent ce2d890 commit a7b9a41

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3543,7 +3543,8 @@ protected void createStoragePoolMappingsForVolumes(VirtualMachineProfile profile
35433543
protected boolean shouldMapVolume(VirtualMachineProfile profile, StoragePoolVO currentPool) {
35443544
boolean isManaged = currentPool.isManaged();
35453545
boolean isNotKvm = HypervisorType.KVM != profile.getHypervisorType();
3546-
return isNotKvm || isManaged;
3546+
boolean isClvm = ClvmPoolManager.isClvmPoolType(currentPool.getPoolType());
3547+
return isNotKvm || isManaged || isClvm;
35473548
}
35483549

35493550
/**

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
408408
answer = new Answer(cmd, false, errMsg);
409409
} else {
410410
answer = ep.sendMessage(cmd);
411+
if (answer != null && answer.getResult()) {
412+
setClvmLockHostIdIfApplicable(destData, ep);
413+
}
411414
}
412415
return answer;
413416
}
@@ -463,6 +466,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
463466
imageStore.delete(objOnImageStore);
464467
return answer;
465468
}
469+
setClvmLockHostIdIfApplicable(destData, ep);
466470
} catch (Exception e) {
467471
if (imageStore.exists(objOnImageStore)) {
468472
objOnImageStore.processEvent(Event.OperationFailed);
@@ -486,6 +490,9 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
486490
answer = new Answer(cmd, false, errMsg);
487491
} else {
488492
answer = ep.sendMessage(cmd);
493+
if (answer != null && answer.getResult()) {
494+
setClvmLockHostIdIfApplicable(destData, ep);
495+
}
489496
}
490497
// delete volume on cache store
491498
if (cacheData != null) {
@@ -495,6 +502,17 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
495502
}
496503
}
497504

505+
private void setClvmLockHostIdIfApplicable(DataObject destData, EndPoint ep) {
506+
if (ep == null || !(destData instanceof VolumeInfo)) {
507+
return;
508+
}
509+
VolumeInfo destVolume = (VolumeInfo) destData;
510+
if (ClvmPoolManager.isClvmPoolType(destVolume.getStoragePoolType())) {
511+
clvmPoolManager.setClvmLockHostId(destVolume.getId(), ep.getId());
512+
logger.debug("Set CLVM lock host {} for migrated volume {}", ep.getId(), destVolume.getUuid());
513+
}
514+
}
515+
498516
private boolean canBypassSecondaryStorage(DataObject srcData, DataObject destData) {
499517
if (srcData instanceof VolumeInfo) {
500518
if (((VolumeInfo)srcData).isDirectDownload()) {
@@ -613,6 +631,9 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
613631
if (destPool.getPoolType() == StoragePoolType.CLVM) {
614632
volumeVo.setFormat(ImageFormat.RAW);
615633
}
634+
if (ClvmPoolManager.isClvmPoolType(destPool.getPoolType())) {
635+
clvmPoolManager.setClvmLockHostId(volume.getId(), ep.getId());
636+
}
616637
// For SMB, pool credentials are also stored in the uri query string. We trim the query string
617638
// part here to make sure the credentials do not get stored in the db unencrypted.
618639
String folder = destPool.getPath();

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,12 @@ public boolean isLockTransferRequired(VolumeInfo volumeToAttach, StoragePoolType
30963096
}
30973097

30983098
if (volumePoolId == null || !volumePoolId.equals(vmPoolId)) {
3099+
Long volumeLockHostId = findVolumeLockHost(volumeToAttach);
3100+
if (volumeLockHostId != null && vmHostId != null && !volumeLockHostId.equals(vmHostId)) {
3101+
logger.info("CLVM cross-pool lock transfer required: Volume {} on pool {} lock is on host {} but VM is on host {}",
3102+
volumeToAttach.getUuid(), volumePoolId, volumeLockHostId, vmHostId);
3103+
return true;
3104+
}
30993105
return false;
31003106
}
31013107

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7022,7 +7022,7 @@ private static boolean isClvmVolume(DiskDef disk, VirtualMachineTO vmSpec) {
70227022
continue;
70237023
}
70247024
VolumeObjectTO volumeTO = (VolumeObjectTO) diskTO.getData();
7025-
if (!diskPath.equals(volumeTO.getPath()) && !diskPath.equals(diskTO.getPath())) {
7025+
if (!diskPath.substring(diskPath.lastIndexOf(File.separator) + 1).equals(volumeTO.getPath())) {
70267026
continue;
70277027
}
70287028
DataStoreTO dataStore = volumeTO.getDataStore();

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,16 +437,10 @@ public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimary
437437
try {
438438
EndPoint ep = null;
439439
VolumeInfo volumeInfo = volFactory.getVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
440-
441-
StoragePoolVO storagePool = primaryStoreDao.findById(volumeInfo.getPoolId());
442-
if (storagePool != null && storagePool.getPoolType() == StoragePoolType.CLVM) {
443-
ep = epSelector.select(volumeInfo);
440+
if (snapshotOnPrimaryStore != null) {
441+
ep = epSelector.select(snapshotOnPrimaryStore);
444442
} else {
445-
if (snapshotOnPrimaryStore != null) {
446-
ep = epSelector.select(snapshotOnPrimaryStore);
447-
} else {
448-
ep = epSelector.select(volumeInfo);
449-
}
443+
ep = epSelector.select(volumeInfo);
450444
}
451445

452446
if ( ep == null ){

0 commit comments

Comments
 (0)