Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4d54125

Browse filesBrowse files
authored
CLVM: Fix volume mapping and disk path matching for storage migration (#13468)
1 parent 4816e05 commit 4d54125
Copy full SHA for 4d54125

7 files changed

+76-15Lines changed: 76 additions & 15 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+2-1Lines 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
/**
Collapse file

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

Copy file name to clipboardExpand all lines: engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
445445
answer = new Answer(cmd, false, errMsg);
446446
} else {
447447
answer = ep.sendMessage(cmd);
448+
if (answer != null && answer.getResult()) {
449+
setClvmLockHostIdIfApplicable(destData, ep);
450+
}
448451
}
449452
return answer;
450453
}
@@ -500,6 +503,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
500503
imageStore.delete(objOnImageStore);
501504
return answer;
502505
}
506+
setClvmLockHostIdIfApplicable(destData, ep);
503507
} catch (Exception e) {
504508
if (imageStore.exists(objOnImageStore)) {
505509
objOnImageStore.processEvent(Event.OperationFailed);
@@ -523,6 +527,9 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
523527
answer = new Answer(cmd, false, errMsg);
524528
} else {
525529
answer = ep.sendMessage(cmd);
530+
if (answer != null && answer.getResult()) {
531+
setClvmLockHostIdIfApplicable(destData, ep);
532+
}
526533
}
527534
// delete volume on cache store
528535
if (cacheData != null) {
@@ -532,6 +539,17 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
532539
}
533540
}
534541

542+
private void setClvmLockHostIdIfApplicable(DataObject destData, EndPoint ep) {
543+
if (ep == null || !(destData instanceof VolumeInfo)) {
544+
return;
545+
}
546+
VolumeInfo destVolume = (VolumeInfo) destData;
547+
if (ClvmPoolManager.isClvmPoolType(destVolume.getStoragePoolType())) {
548+
clvmPoolManager.setClvmLockHostId(destVolume.getId(), ep.getId());
549+
logger.debug("Set CLVM lock host {} for migrated volume {}", ep.getId(), destVolume.getUuid());
550+
}
551+
}
552+
535553
private boolean canBypassSecondaryStorage(DataObject srcData, DataObject destData) {
536554
if (srcData instanceof VolumeInfo) {
537555
if (((VolumeInfo)srcData).isDirectDownload()) {
@@ -650,6 +668,9 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
650668
if (destPool.getPoolType() == StoragePoolType.CLVM) {
651669
volumeVo.setFormat(ImageFormat.RAW);
652670
}
671+
if (ClvmPoolManager.isClvmPoolType(destPool.getPoolType())) {
672+
clvmPoolManager.setClvmLockHostId(volume.getId(), ep.getId());
673+
}
653674
// For SMB, pool credentials are also stored in the uri query string. We trim the query string
654675
// part here to make sure the credentials do not get stored in the db unencrypted.
655676
String folder = destPool.getPath();
Collapse file

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

Copy file name to clipboardExpand all lines: engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,12 @@ public boolean isLockTransferRequired(VolumeInfo volumeToAttach, StoragePoolType
31183118
}
31193119

31203120
if (volumePoolId == null || !volumePoolId.equals(vmPoolId)) {
3121+
Long volumeLockHostId = findVolumeLockHost(volumeToAttach);
3122+
if (volumeLockHostId != null && vmHostId != null && !volumeLockHostId.equals(vmHostId)) {
3123+
logger.info("CLVM cross-pool lock transfer required: Volume {} on pool {} lock is on host {} but VM is on host {}",
3124+
volumeToAttach.getUuid(), volumePoolId, volumeLockHostId, vmHostId);
3125+
return true;
3126+
}
31213127
return false;
31223128
}
31233129

Collapse file

‎engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceImplClvmTest.java‎

Copy file name to clipboardExpand all lines: engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceImplClvmTest.java
+37-2Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,49 @@ public void testIsLockTransferRequired_NonCLVMPool() {
167167
}
168168

169169
@Test
170-
public void testIsLockTransferRequired_DifferentPools() {
170+
public void testIsLockTransferRequired_DifferentPools_LockOnDifferentHost() {
171+
when(volumeService.findVolumeLockHost(volumeInfoMock)).thenReturn(HOST_ID_2);
172+
173+
assertTrue(volumeService.isLockTransferRequired(
174+
volumeInfoMock, StoragePoolType.CLVM, StoragePoolType.CLVM,
175+
POOL_ID_1, POOL_ID_2, HOST_ID_1));
176+
}
177+
178+
@Test
179+
public void testIsLockTransferRequired_DifferentPools_LockOnSameHost() {
180+
when(volumeService.findVolumeLockHost(volumeInfoMock)).thenReturn(HOST_ID_1);
181+
182+
assertFalse(volumeService.isLockTransferRequired(
183+
volumeInfoMock, StoragePoolType.CLVM, StoragePoolType.CLVM,
184+
POOL_ID_1, POOL_ID_2, HOST_ID_1));
185+
}
186+
187+
@Test
188+
public void testIsLockTransferRequired_DifferentPools_NoLockHost() {
189+
when(volumeService.findVolumeLockHost(volumeInfoMock)).thenReturn(null);
190+
171191
assertFalse(volumeService.isLockTransferRequired(
172192
volumeInfoMock, StoragePoolType.CLVM, StoragePoolType.CLVM,
173193
POOL_ID_1, POOL_ID_2, HOST_ID_1));
174194
}
175195

176196
@Test
177-
public void testIsLockTransferRequired_NullPoolIds() {
197+
public void testIsLockTransferRequired_NullPoolIds_LockOnDifferentHost() {
198+
when(volumeService.findVolumeLockHost(volumeInfoMock)).thenReturn(HOST_ID_2);
199+
200+
assertTrue(volumeService.isLockTransferRequired(
201+
volumeInfoMock, StoragePoolType.CLVM, StoragePoolType.CLVM,
202+
null, POOL_ID_1, HOST_ID_1));
203+
204+
assertTrue(volumeService.isLockTransferRequired(
205+
volumeInfoMock, StoragePoolType.CLVM, StoragePoolType.CLVM,
206+
POOL_ID_1, null, HOST_ID_1));
207+
}
208+
209+
@Test
210+
public void testIsLockTransferRequired_NullPoolIds_NoLockHost() {
211+
when(volumeService.findVolumeLockHost(volumeInfoMock)).thenReturn(null);
212+
178213
assertFalse(volumeService.isLockTransferRequired(
179214
volumeInfoMock, StoragePoolType.CLVM, StoragePoolType.CLVM,
180215
null, POOL_ID_1, HOST_ID_1));
Collapse file

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

Copy file name to clipboardExpand all lines: plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7038,7 +7038,7 @@ private static boolean isClvmVolume(DiskDef disk, VirtualMachineTO vmSpec) {
70387038
continue;
70397039
}
70407040
VolumeObjectTO volumeTO = (VolumeObjectTO) diskTO.getData();
7041-
if (!diskPath.equals(volumeTO.getPath()) && !diskPath.equals(diskTO.getPath())) {
7041+
if (!diskPath.substring(diskPath.lastIndexOf(File.separator) + 1).equals(volumeTO.getPath())) {
70427042
continue;
70437043
}
70447044
DataStoreTO dataStore = volumeTO.getDataStore();
Collapse file

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

Copy file name to clipboardExpand all lines: plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
570570

571571
final VolumeObjectTO newVol = new VolumeObjectTO();
572572
newVol.setPath(vol.getName());
573-
newVol.setSize(volume.getSize());
573+
if (StoragePoolType.CLVM_NG.equals(primaryStore.getPoolType()) && vol != null && vol.getVirtualSize() > 0) {
574+
newVol.setSize(vol.getVirtualSize());
575+
} else {
576+
newVol.setSize(volume.getSize());
577+
}
574578
if (vol.getQemuEncryptFormat() != null) {
575579
newVol.setEncryptFormat(vol.getQemuEncryptFormat().toString());
576580
}
Collapse file

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

Copy file name to clipboardExpand all lines: plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,11 @@ public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimary
436436
CommandResult result = new CommandResult();
437437
try {
438438
EndPoint ep = null;
439-
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);
439+
if (snapshotOnPrimaryStore != null) {
440+
ep = epSelector.select(snapshotOnPrimaryStore);
444441
} else {
445-
if (snapshotOnPrimaryStore != null) {
446-
ep = epSelector.select(snapshotOnPrimaryStore);
447-
} else {
448-
ep = epSelector.select(volumeInfo);
449-
}
442+
VolumeInfo volumeInfo = volFactory.getVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
443+
ep = epSelector.select(volumeInfo);
450444
}
451445

452446
if ( ep == null ){

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.