Skip to content
Open
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
10 changes: 10 additions & 0 deletions server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3490,6 +3490,7 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
StoragePoolVO destinationStoragePoolVo = _storagePoolDao.findById(storagePoolId);

if (isSourceOrDestNotOnStorPool(srcStoragePoolVO, destinationStoragePoolVo)) {
checkKvmLiveMigrationFromManagedPool(vol, srcStoragePoolVO, storagePoolId);
throw new InvalidParameterValueException("KVM does not support volume live migration due to the limited possibility to refresh VM XML domain. " +
"Therefore, to live migrate a volume between storage pools, one must migrate the VM to a different host as well to force the VM XML domain update. " +
"Use 'migrateVirtualMachineWithVolumes' instead.");
Expand Down Expand Up @@ -3679,6 +3680,15 @@ private void checkVmStateForMigration(VMInstanceVO vm, VolumeVO vol) {
}
}

// migrateVirtualMachineWithVolumes refuses this too, so dont point the user there
protected void checkKvmLiveMigrationFromManagedPool(VolumeVO vol, StoragePoolVO srcPool, Long destPoolId) {
if (srcPool.isManaged() && destPoolId != null && srcPool.getId() != destPoolId) {
throw new InvalidParameterValueException(String.format("Volume %s is on managed storage pool %s. " +
"Moving a volume off managed storage while its VM is running is not supported on KVM. " +
"Detach the volume or stop the VM, then migrate it.", vol.getName(), srcPool.getName()));
}
}

private boolean isSourceOrDestNotOnStorPool(StoragePoolVO storagePoolVO, StoragePoolVO destinationStoragePoolVo) {
return storagePoolVO.getPoolType() != Storage.StoragePoolType.StorPool
|| destinationStoragePoolVo.getPoolType() != Storage.StoragePoolType.StorPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2504,4 +2504,28 @@ public void testResizeVolumeInternal_VMware_VMRunning_ShouldThrowStateGuardError
e.getMessage() != null && e.getMessage().contains("VM should be in"));
}
}

@Test
public void checkKvmLiveMigrationFromManagedPoolRejectsMovingOffManagedPool() {
VolumeVO vol = Mockito.mock(VolumeVO.class);
Mockito.when(vol.getName()).thenReturn("DATA-24");
StoragePoolVO src = Mockito.mock(StoragePoolVO.class);
Mockito.when(src.isManaged()).thenReturn(true);
Mockito.when(src.getId()).thenReturn(5L);
Mockito.when(src.getName()).thenReturn("pure-fc-neg");
try {
volumeApiServiceImpl.checkKvmLiveMigrationFromManagedPool(vol, src, 3L);
Assert.fail("expected the migration to be rejected");
} catch (InvalidParameterValueException e) {
Assert.assertTrue(e.getMessage().contains("Detach the volume or stop the VM"));
Assert.assertFalse(e.getMessage().contains("migrateVirtualMachineWithVolumes"));
}
}

@Test
public void checkKvmLiveMigrationFromManagedPoolIgnoresUnmanagedPool() {
StoragePoolVO src = Mockito.mock(StoragePoolVO.class);
Mockito.when(src.isManaged()).thenReturn(false);
volumeApiServiceImpl.checkKvmLiveMigrationFromManagedPool(Mockito.mock(VolumeVO.class), src, 3L);
}
}
Loading