DaanHoogland commented on code in PR #8067:
URL: https://github.com/apache/cloudstack/pull/8067#discussion_r1358140371


##########
plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java:
##########
@@ -690,24 +770,173 @@ public void revertSnapshot(
         }
     }
 
+    private static boolean canCopyTemplateCond(DataObject srcData, DataObject 
dstData) {
+        return srcData.getType() == DataObjectType.TEMPLATE && 
dstData.getType() == DataObjectType.TEMPLATE
+            && dstData.getDataStore().getRole() == DataStoreRole.Primary
+            && (srcData.getDataStore().getRole() == DataStoreRole.Image
+            || srcData.getDataStore().getRole() == DataStoreRole.ImageCache);
+    }
+
     @Override
-    public boolean canCopy(DataObject srcData, DataObject destData)
+    public boolean canCopy(DataObject srcData, DataObject dstData)
     {
+        s_logger.debug("LinstorPrimaryDataStoreDriverImpl.canCopy: " + 
srcData.getType() + " -> " + dstData.getType());
+
+        if (srcData.getType() == DataObjectType.SNAPSHOT && dstData.getType() 
== DataObjectType.SNAPSHOT
+            && (dstData.getDataStore().getRole() == DataStoreRole.Image
+                || dstData.getDataStore().getRole() == 
DataStoreRole.ImageCache)) {
+            SnapshotInfo sinfo = (SnapshotInfo) srcData;
+            VolumeInfo volume = sinfo.getBaseVolume();
+            StoragePoolVO storagePool = 
_storagePoolDao.findById(volume.getPoolId());
+            return 
storagePool.getStorageProviderName().equals(LinstorUtil.PROVIDER_NAME);
+        } else if (canCopyTemplateCond(srcData, dstData)) {
+            StoragePoolVO storagePoolVO = 
_storagePoolDao.findById(dstData.getDataStore().getId());
+            return storagePoolVO != null && storagePoolVO.getPoolType() == 
Storage.StoragePoolType.Linstor;
+        }
         return false;
     }
 
     @Override
-    public void copyAsync(DataObject srcData, DataObject destData, 
AsyncCompletionCallback<CopyCommandResult> callback)
+    public void copyAsync(DataObject srcData, DataObject dstData, 
AsyncCompletionCallback<CopyCommandResult> callback)
     {
-        // as long as canCopy is false, this isn't called
-        s_logger.debug("Linstor: copyAsync with srcdata: " + 
srcData.getUuid());
+        s_logger.debug("LinstorPrimaryDataStoreDriverImpl.copyAsync: "
+            + srcData.getType() + " -> " + dstData.getType());
+
+        final CopyCommandResult res;
+        if (srcData.getType() == DataObjectType.SNAPSHOT && dstData.getType() 
== DataObjectType.SNAPSHOT
+                && (dstData.getDataStore().getRole() == DataStoreRole.Image
+                    || dstData.getDataStore().getRole() == 
DataStoreRole.ImageCache)) {

Review Comment:
   sorry, I missed it (and am not perfect) I think it will help readability.



-- 
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]

Reply via email to