Skip to content

Commit c2b664d

Browse files
author
Pearl Dsilva
committed
if vmmigration with volume is done to the same clvm volume group, then dont do data transfer, just lock transfer and vm
1 parent f29d8a2 commit c2b664d

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,18 @@ public void migrateVolumes(VirtualMachine vm, VirtualMachineTO vmTo, Host srcHos
16751675
for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
16761676
Volume volume = entry.getKey();
16771677
StoragePool destPool = entry.getValue();
1678-
updateClvmLockHostAfterMigration(volume, destPool, "vm-migrated");
1678+
StoragePoolVO srcPool = _storagePoolDao.findById(volume.getPoolId());
1679+
if (srcPool != null && srcPool.getId() == destPool.getId() &&
1680+
ClvmPoolManager.isClvmPoolType(srcPool.getPoolType())) {
1681+
if (!clvmPoolManager.transferClvmVolumeLock(volume.getUuid(), volume.getId(),
1682+
volume.getPath(), srcPool, srcHost.getId(), destHost.getId())) {
1683+
throw new CloudRuntimeException(String.format(
1684+
"Failed to transfer CLVM lock for volume [%s] to destination host [%s].",
1685+
volume.getUuid(), destHost.getId()));
1686+
}
1687+
} else {
1688+
updateClvmLockHostAfterMigration(volume, destPool, "vm-migrated");
1689+
}
16791690
}
16801691
} catch (InterruptedException | ExecutionException e) {
16811692
logger.error("Failed to migrate VM [{}] along with its volumes due to [{}].", vm, e.getMessage());

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.cloud.agent.api.PrepareForMigrationAnswer;
3838
import com.cloud.resource.ResourceManager;
3939
import com.cloud.storage.clvm.ClvmPoolManager;
40+
import org.apache.cloudstack.storage.clvm.command.ClvmLockTransferCommand;
4041
import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
4142
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
4243
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
@@ -2027,6 +2028,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20272028
String errMsg = null;
20282029
boolean success = false;
20292030
Map<VolumeInfo, VolumeInfo> srcVolumeInfoToDestVolumeInfo = new HashMap<>();
2031+
List<VolumeInfo> samePoolClvmVolumes = new ArrayList<>();
20302032

20312033
try {
20322034
if (srcHost.getHypervisorType() != HypervisorType.KVM) {
@@ -2056,6 +2058,13 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20562058
continue;
20572059
}
20582060

2061+
if (sourceStoragePool.getId() == destStoragePool.getId() &&
2062+
ClvmPoolManager.isClvmPoolType(destStoragePool.getPoolType())) {
2063+
logger.info("Same-pool CLVM migration for volume [{}]: skipping data copy.", srcVolumeInfo.getUuid());
2064+
samePoolClvmVolumes.add(srcVolumeInfo);
2065+
continue;
2066+
}
2067+
20592068
if (!shouldMigrateVolume(sourceStoragePool, destHost, destStoragePool)) {
20602069
continue;
20612070
}
@@ -2148,6 +2157,23 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
21482157
throw new AgentUnavailableException("Operation timed out", destHost.getId());
21492158
}
21502159

2160+
for (VolumeInfo vol : samePoolClvmVolumes) {
2161+
StoragePoolVO samePoolClvmPool = _storagePoolDao.findById(vol.getPoolId());
2162+
String vgName = samePoolClvmPool.getPath();
2163+
if (vgName.startsWith("/")) vgName = vgName.substring(1);
2164+
String lvPath = String.format("/dev/%s/%s", vgName, vol.getPath());
2165+
logger.info("Activating CLVM volume [{}] in shared mode on dest host [{}] for same-pool migration.",
2166+
vol.getUuid(), destHost.getId());
2167+
Answer activateAnswer = agentManager.send(destHost.getId(),
2168+
new ClvmLockTransferCommand(ClvmLockTransferCommand.Operation.ACTIVATE_SHARED, lvPath, vol.getUuid()));
2169+
if (activateAnswer == null || !activateAnswer.getResult()) {
2170+
throw new CloudRuntimeException(String.format(
2171+
"Failed to activate CLVM volume [%s] in shared mode on dest host [%s]: %s",
2172+
vol.getUuid(), destHost.getId(),
2173+
activateAnswer != null ? activateAnswer.getDetails() : "null answer"));
2174+
}
2175+
}
2176+
21512177
VMInstanceVO vm = _vmDao.findById(vmTO.getId());
21522178
boolean isWindows = _guestOsCategoryDao.findById(_guestOsDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
21532179

0 commit comments

Comments
 (0)