rg9975 commented on code in PR #7889:
URL: https://github.com/apache/cloudstack/pull/7889#discussion_r1374807550
##########
engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java:
##########
@@ -826,24 +840,73 @@ private void handleFailedVolumeMigration(VolumeInfo
srcVolumeInfo, VolumeInfo de
_volumeDao.update(srcVolumeInfo.getId(), volumeVO);
}
- private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo,
VolumeInfo destVolumeInfo) {
+ private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo,
VolumeInfo destVolumeInfo, AsyncCompletionCallback<CopyCommandResult> callback)
{
VirtualMachine vm = srcVolumeInfo.getAttachedVM();
- if (vm != null && vm.getState() != VirtualMachine.State.Stopped) {
- throw new CloudRuntimeException("Currently, if a volume to migrate
from non-managed storage to managed storage on KVM is attached to " +
- "a VM, the VM must be in the Stopped state.");
- }
+ checkAvailableForMigration(vm);
-
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(),
destVolumeInfo, null);
+ String errMsg = null;
+ try {
+
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(),
destVolumeInfo, null);
+ VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId());
+ updatePathFromScsiName(volumeVO);
+ destVolumeInfo =
_volumeDataFactory.getVolume(destVolumeInfo.getId(),
destVolumeInfo.getDataStore());
+ HostVO hostVO =
getHostOnWhichToExecuteMigrationCommand(srcVolumeInfo, destVolumeInfo);
- VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId());
+ // migrate the volume via the hypervisor
+ String path = migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo,
hostVO, "Unable to migrate the volume from non-managed storage to managed
storage");
- volumeVO.setPath(volumeVO.get_iScsiName());
+ updateVolumePath(destVolumeInfo.getId(), path);
+ volumeVO = _volumeDao.findById(destVolumeInfo.getId());
+ // only set this if it was not set. default to QCOW2 for KVM
+ if (volumeVO.getFormat() == null) {
+ volumeVO.setFormat(ImageFormat.QCOW2);
+ _volumeDao.update(volumeVO.getId(), volumeVO);
+ }
+ } catch (Exception ex) {
+ errMsg = "Primary storage migration failued due to an unexpected
error: " +
+ ex.getMessage();
+ if (ex instanceof CloudRuntimeException) {
+ throw ex;
+ } else {
+ throw new CloudRuntimeException(errMsg, ex);
+ }
+ } finally {
+ CopyCmdAnswer copyCmdAnswer;
+ if (errMsg != null) {
+ copyCmdAnswer = new CopyCmdAnswer(errMsg);
+ }
+ else {
+ destVolumeInfo =
_volumeDataFactory.getVolume(destVolumeInfo.getId(),
destVolumeInfo.getDataStore());
+ DataTO dataTO = destVolumeInfo.getTO();
+ copyCmdAnswer = new CopyCmdAnswer(dataTO);
+ }
- _volumeDao.update(volumeVO.getId(), volumeVO);
+ CopyCommandResult result = new CopyCommandResult(null,
copyCmdAnswer);
+ result.setResult(errMsg);
+ callback.complete(result);
+ }
+ }
- destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(),
destVolumeInfo.getDataStore());
+ private void checkAvailableForMigration(VirtualMachine vm) {
Review Comment:
Yes, upcoming commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]