nvazquez commented on a change in pull request #5349:
URL: https://github.com/apache/cloudstack/pull/5349#discussion_r693890850



##########
File path: 
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
##########
@@ -1639,6 +1673,74 @@ public Answer createVolumeFromSnapshot(final CopyCommand 
cmd) {
         }
     }
 
+    private KVMPhysicalDisk createRBDvolumeFromRBDSnapshot(KVMPhysicalDisk 
volume, String snapshotName, String name,
+            PhysicalDiskFormat format, long size, KVMStoragePool destPool, int 
timeout) {
+
+        KVMStoragePool srcPool = volume.getPool();
+        KVMPhysicalDisk disk = null;
+        String newUuid = name;
+        int rbdFeatures = 61;
+
+        format = PhysicalDiskFormat.RAW;
+        disk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + newUuid, 
newUuid, destPool);
+        disk.setFormat(format);
+        if (size > volume.getVirtualSize()) {

Review comment:
       What about:
   ````
   disk.setSize(size > volume.getVirtualSize() ? size : 
volume.getVirtualSize());
   disk.setVirtualSize(size > volume.getVirtualSize() ? size : disk.getSize());
   ````

##########
File path: 
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
##########
@@ -1639,6 +1673,74 @@ public Answer createVolumeFromSnapshot(final CopyCommand 
cmd) {
         }
     }
 
+    private KVMPhysicalDisk createRBDvolumeFromRBDSnapshot(KVMPhysicalDisk 
volume, String snapshotName, String name,
+            PhysicalDiskFormat format, long size, KVMStoragePool destPool, int 
timeout) {
+
+        KVMStoragePool srcPool = volume.getPool();
+        KVMPhysicalDisk disk = null;
+        String newUuid = name;
+        int rbdFeatures = 61;

Review comment:
       Minor: if this is the same as `LibvirtStorageAdaptor.rbdFeatures`, can 
we expose it and use it instead of a new variable on this method?

##########
File path: 
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
##########
@@ -1639,6 +1673,74 @@ public Answer createVolumeFromSnapshot(final CopyCommand 
cmd) {
         }
     }
 
+    private KVMPhysicalDisk createRBDvolumeFromRBDSnapshot(KVMPhysicalDisk 
volume, String snapshotName, String name,
+            PhysicalDiskFormat format, long size, KVMStoragePool destPool, int 
timeout) {
+
+        KVMStoragePool srcPool = volume.getPool();
+        KVMPhysicalDisk disk = null;
+        String newUuid = name;
+        int rbdFeatures = 61;
+
+        format = PhysicalDiskFormat.RAW;
+        disk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + newUuid, 
newUuid, destPool);
+        disk.setFormat(format);
+        if (size > volume.getVirtualSize()) {
+            disk.setSize(size);
+            disk.setVirtualSize(size);
+        } else {
+            disk.setSize(volume.getVirtualSize());
+            disk.setVirtualSize(disk.getSize());
+        }
+
+        try {
+
+            Rados r = new Rados(srcPool.getAuthUserName());
+            r.confSet("mon_host", srcPool.getSourceHost() + ":" + 
srcPool.getSourcePort());
+            r.confSet("key", srcPool.getAuthSecret());
+            r.confSet("client_mount_timeout", "30");
+            r.connect();
+
+            IoCTX io = r.ioCtxCreate(srcPool.getSourceDir());
+            Rbd rbd = new Rbd(io);
+            RbdImage srcImage = rbd.open(volume.getName());
+
+            List<RbdSnapInfo> snaps = srcImage.snapList();
+            boolean snapFound = false;
+            for (RbdSnapInfo snap : snaps) {
+                if (snapshotName.equals(snap.name)) {
+                    snapFound = true;
+                    break;
+                }
+            }
+
+            if (!snapFound) {
+                return null;

Review comment:
       Maybe add a log line as well to help debugging/tracing errors?




-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to