Github user mike-tutkowski commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1403#discussion_r52114579 --- Diff: engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java --- @@ -255,99 +332,149 @@ private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(SnapshotInfo snap VolumeApiResult result = future.get(); + if (volumeDetail != null) { + _volumeDetailsDao.remove(volumeDetail.getId()); + } + if (result.isFailed()) { s_logger.debug("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } - } - catch (Exception ex) { - throw new CloudRuntimeException(ex.getMessage()); - } - - volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); - volumeInfo.processEvent(Event.MigrationRequested); + volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); - volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); + volumeInfo.processEvent(Event.MigrationRequested); - HostVO hostVO = getHost(snapshotInfo.getDataStore().getId()); + volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); - String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString()); - int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue())); - CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value()); + if (useCloning) { + copyCmdAnswer = performResignature(volumeInfo, hostVO); + } + else { + // asking for a XenServer host here so we don't always prefer to use XenServer hosts that support resigning + // even when we don't need those hosts to do this kind of copy work + hostVO = getXenServerHost(snapshotInfo.getDataCenterId(), false); - CopyCmdAnswer copyCmdAnswer = null; + copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO); + } - try { - _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore()); - _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore()); + if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { + if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) { + errMsg = copyCmdAnswer.getDetails(); + } + else { + errMsg = "Unable to perform host-side operation"; + } + } + } + catch (Exception ex) { + errMsg = ex.getMessage() != null ? ex.getMessage() : "Copy operation failed"; + } - Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()), snapshotInfo); + CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer); - copyCommand.setOptions(srcDetails); + result.setResult(errMsg); - Map<String, String> destDetails = getVolumeDetails(volumeInfo); + callback.complete(result); + } - copyCommand.setOptions2(destDetails); + // If the underlying storage system is making use of read-only snapshots, this gives the storage system the opportunity to + // create a volume from the snapshot so that we can copy the VHD file that should be inside of the snapshot to secondary storage. + // + // The resultant volume must be writable because we need to resign the SR and the VDI that should be inside of it before we copy + // the VHD file to secondary storage. + // + // If the storage system is using writable snapshots, then nothing need be done by that storage system here because we can just + // resign the SR and the VDI that should be inside of the snapshot before copying the VHD file to secondary storage. + private void createVolumeFromSnapshot(HostVO hostVO, SnapshotInfo snapshotInfo, boolean keepGrantedAccess) { --- End diff -- Done - thanks
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---