[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-9620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16310445#comment-16310445
 ] 

ASF GitHub Bot commented on CLOUDSTACK-9620:
--------------------------------------------

DaanHoogland commented on a change in pull request #2298: CLOUDSTACK-9620: 
Enhancements for managed storage
URL: https://github.com/apache/cloudstack/pull/2298#discussion_r159545477
 
 

 ##########
 File path: 
engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
 ##########
 @@ -684,40 +1237,154 @@ private void 
handleCreateVolumeFromSnapshotBothOnStorageSystem(SnapshotInfo snap
             }
 
             volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), 
volumeInfo.getDataStore());
-
             volumeInfo.processEvent(Event.MigrationRequested);
-
             volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), 
volumeInfo.getDataStore());
 
-            if (useCloning) {
-                copyCmdAnswer = performResignature(volumeInfo, hostVO);
+            if 
(HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType()) || 
HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
+                if (useCloning) {
+                    Map<String, String> extraDetails = null;
+
+                    if 
(HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
+                        extraDetails = new HashMap<>();
+
+                        String extraDetailsVmdk = 
getSnapshotProperty(snapshotInfo.getId(), DiskTO.VMDK);
+
+                        extraDetails.put(DiskTO.VMDK, extraDetailsVmdk);
+                    }
+
+                    copyCmdAnswer = performResignature(volumeInfo, hostVO, 
extraDetails);
+
+                    // If using VMware, have the host rescan its software HBA 
if dynamic discovery is in use.
+                    if 
(HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
+                        disconnectHostFromVolume(hostVO, 
volumeInfo.getPoolId(), volumeInfo.get_iScsiName());
+                    }
+                } 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 = getHost(snapshotInfo.getDataCenterId(), 
snapshotInfo.getHypervisorType(), false);
+
+                    copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, 
hostVO);
+                }
+
+                if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
+                    if (copyCmdAnswer != null && 
!StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
+                        throw new 
CloudRuntimeException(copyCmdAnswer.getDetails());
+                    } else {
+                        throw new CloudRuntimeException("Unable to create 
volume from snapshot");
+                    }
+                }
+            }
+            else if 
(HypervisorType.KVM.equals(snapshotInfo.getHypervisorType())) {
+                VolumeObjectTO newVolume = new VolumeObjectTO();
+
+                newVolume.setSize(volumeInfo.getSize());
+                newVolume.setPath(volumeInfo.get_iScsiName());
+                newVolume.setFormat(volumeInfo.getFormat());
+
+                copyCmdAnswer = new CopyCmdAnswer(newVolume);
             }
             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 = getHost(snapshotInfo.getDataCenterId(), false);
+                throw new CloudRuntimeException("Unsupported hypervisor type");
+            }
+        }
+        catch (Exception ex) {
+            errMsg = "Copy operation failed in 
'StorageSystemDataMotionStrategy.handleCreateVolumeFromSnapshotBothOnStorageSystem':
 " +
+                    ex.getMessage();
 
-                copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, 
hostVO);
+            throw new CloudRuntimeException(errMsg);
+        }
+        finally {
+            if (copyCmdAnswer == null) {
+                copyCmdAnswer = new CopyCmdAnswer(errMsg);
             }
 
+            CopyCommandResult result = new CopyCommandResult(null, 
copyCmdAnswer);
+
+            result.setResult(errMsg);
+
+            callback.complete(result);
+        }
+    }
+
+    private void handleCreateVolumeFromVolumeOnSecondaryStorage(VolumeInfo 
srcVolumeInfo, VolumeInfo destVolumeInfo,
+                                                                long 
dataCenterId, HypervisorType hypervisorType,
+                                                                
AsyncCompletionCallback<CopyCommandResult> callback) {
+        String errMsg = null;
+        CopyCmdAnswer copyCmdAnswer = null;
+
+        try {
+            // create a volume on the storage
+            
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(),
 destVolumeInfo, null);
+
+            destVolumeInfo = 
_volumeDataFactory.getVolume(destVolumeInfo.getId(), 
destVolumeInfo.getDataStore());
+
+            HostVO hostVO = getHost(dataCenterId, hypervisorType, false);
+
+            // copy the volume from secondary via the hypervisor
+            copyCmdAnswer = copyImageToVolume(srcVolumeInfo, destVolumeInfo, 
hostVO);
+
             if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
                 if (copyCmdAnswer != null && 
!StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
-                    errMsg = copyCmdAnswer.getDetails();
+                    throw new 
CloudRuntimeException(copyCmdAnswer.getDetails());
                 }
                 else {
-                    errMsg = "Unable to create volume from snapshot";
+                    throw new CloudRuntimeException("Unable to create volume 
from volume");
                 }
             }
         }
         catch (Exception ex) {
-            errMsg = ex.getMessage() != null ? ex.getMessage() : "Copy 
operation failed in 
'StorageSystemDataMotionStrategy.handleCreateVolumeFromSnapshotBothOnStorageSystem'";
+            errMsg = "Copy operation failed in 
'StorageSystemDataMotionStrategy.handleCreateVolumeFromVolumeOnSecondaryStorage':
 " +
+                    ex.getMessage();
+
+            throw new CloudRuntimeException(errMsg);
         }
+        finally {
+            if (copyCmdAnswer == null) {
+                copyCmdAnswer = new CopyCmdAnswer(errMsg);
+            }
 
-        CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
+            CopyCommandResult result = new CopyCommandResult(null, 
copyCmdAnswer);
 
-        result.setResult(errMsg);
+            result.setResult(errMsg);
 
-        callback.complete(result);
+            callback.complete(result);
+        }
+    }
+
+    private CopyCmdAnswer copyImageToVolume(DataObject srcDataObject, 
VolumeInfo destVolumeInfo, HostVO hostVO) {
+        String value = 
_configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
+        int primaryStorageDownloadWait = NumbersUtil.parseInt(value, 
Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
+
+        CopyCommand copyCommand = new CopyCommand(srcDataObject.getTO(), 
destVolumeInfo.getTO(), primaryStorageDownloadWait,
+                VirtualMachineManager.ExecuteInSequence.value());
+
+        CopyCmdAnswer copyCmdAnswer;
+
+        try {
+            _volumeService.grantAccess(destVolumeInfo, hostVO, 
destVolumeInfo.getDataStore());
+
+            Map<String, String> destDetails = getVolumeDetails(destVolumeInfo);
+
+            copyCommand.setOptions2(destDetails);
+
+            copyCmdAnswer = (CopyCmdAnswer)_agentMgr.send(hostVO.getId(), 
copyCommand);
+        }
+        catch (CloudRuntimeException | AgentUnavailableException | 
OperationTimedoutException ex) {
+            String msg = "Failed to copy image : ";
+
 
 Review comment:
   I've seen this at several places now. just a remark but these whitelines are 
a bit of noise

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Improvements for Managed Storage
> --------------------------------
>
>                 Key: CLOUDSTACK-9620
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9620
>             Project: CloudStack
>          Issue Type: Improvement
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: KVM, Management Server, VMware, XenServer
>    Affects Versions: 4.11.0.0
>         Environment: KVM, vSphere, and XenServer
>            Reporter: Mike Tutkowski
>            Assignee: Mike Tutkowski
>             Fix For: 4.11.0.0
>
>
> Allowed zone-wide primary storage based on a custom plug-in to be added via 
> the GUI in a KVM-only environment (previously this only worked for XenServer 
> and VMware)
> Added support for root disks on managed storage with KVM
> Added support for volume snapshots with managed storage on KVM
> Enable creating a template directly from a volume (i.e. without having to go 
> through a volume snapshot) on KVM with managed storage
> Only allow the resizing of a volume for managed storage on KVM if the volume 
> in question is either not attached to a VM or is attached to a VM in the 
> Stopped state.
> Included support for Reinstall VM on KVM with managed storage
> Enabled offline migration on KVM from non-managed storage to managed storage 
> and vice versa
> Included support for online storage migration on KVM with managed storage 
> (NFS and Ceph to managed storage)
> Added support to download (extract) a managed-storage volume to a QCOW2 file
> When uploading a file from outside of CloudStack to CloudStack, set the min 
> and max IOPS, if applicable.
> Included support for the KVM auto-convergence feature
> The compression flag was actually added in version 1.0.3 (1000003) as opposed 
> to version 1.3.0 (1003000) (changed this to reflect the correct version)
> On KVM when using iSCSI-based managed storage, if the user shuts a VM down 
> from the guest OS (as opposed to doing so from CloudStack), we need to pass 
> to the KVM agent a list of applicable iSCSI volumes that need to be 
> disconnected.
> Added a new Global Setting: kvm.storage.live.migration.wait
> For XenServer, added a check to enforce that only volumes from zone-wide 
> managed storage can be storage motioned from a host in one cluster to a host 
> in another cluster (cannot do so at the time being with volumes from 
> cluster-scoped managed storage)
> Don’t allow Storage XenMotion on a VM that has any managed-storage volume 
> with one or more snapshots.
> Enabled for managed storage with VMware: Template caching, create snapshot, 
> delete snapshot, create volume from snapshot, and create template from 
> snapshot
> Added an SIOC API plug-in to support VMware SIOC
> When starting a VM that uses managed storage in a cluster other than the one 
> it last was running in, we need to remove the reference to the iSCSI volume 
> from the original cluster.
> Added the ability to revert a volume to a snapshot
> Enable cluster-scoped managed storage
> Add support for VMware dynamic discovery



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to