rajiv-jain-netapp commented on code in PR #14203:
URL: https://github.com/apache/cloudstack/pull/14203#discussion_r4152157990


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -310,36 +328,45 @@ private boolean 
replaceVolumeWithBackup(KVMStoragePoolManager storagePoolMgr, Pr
         if (hasBackingChain(backupPath)) {
             String[] qemuImgCmd = new String[] { 
Script.getExecutableAbsolutePath("qemu-img"), "convert", "-O", "qcow2", 
backupPath, volumePath };
             int flattenExit = Script.executeCommandForExitValue(qemuImgCmd);
-            return flattenExit == 0;
+            return new Pair<>(flattenExit == 0, volumePath);
         }
 
         String[] rsyncCmd = new String[] { 
Script.getExecutableAbsolutePath("rsync"), "-az", backupPath, volumePath };
         int exitValue = Script.executeCommandForExitValue(timeout, rsyncCmd);
-        return exitValue == 0;
+        return new Pair<>(exitValue == 0, volumePath);
     }
 
     private boolean hasBackingChain(String qcow2Path) {
         return Script.runSimpleBashScriptForExitValue(
                 String.format(QEMU_IMG_HAS_BACKING_COMMAND, qcow2Path)) == 0;
     }
 
-    private boolean replaceBlockDeviceWithBackup(KVMStoragePoolManager 
storagePoolMgr, PrimaryDataStoreTO volumePool, String volumePath, String 
backupPath, int timeout, boolean createTargetVolume, Long size) {
+    private Pair<Boolean, String> 
replaceBlockDeviceWithBackup(KVMStoragePoolManager storagePoolMgr, 
PrimaryDataStoreTO volumePool, String volumePath, String backupPath, int 
timeout, boolean createTargetVolume, Long size) {
         KVMStoragePool volumeStoragePool = 
storagePoolMgr.getStoragePool(volumePool.getPoolType(), volumePool.getUuid());
+        Storage.StoragePoolType poolType = volumePool.getPoolType();
         QemuImg qemu;
         try {
             qemu = new QemuImg(timeout, true, false);
             String volumeUuid = getVolumeUuidFromPath(volumePath, volumePool);
             KVMPhysicalDisk disk = null;
             if (createTargetVolume) {
-                if 
(Storage.StoragePoolType.Linstor.equals(volumePool.getPoolType())) {
+                if (Storage.StoragePoolType.Linstor.equals(poolType) || 
Storage.StoragePoolType.StorPool.equals(poolType)) {
                     if (size == null) {
-                        throw new CloudRuntimeException("Restore volume size 
is required for Linstor pool when creating target volume");
+                        throw new CloudRuntimeException(String.format("Restore 
volume size is required for %s pool when creating target volume", poolType));
                     }
                     disk = volumeStoragePool.createPhysicalDisk(volumeUuid, 
QemuImg.PhysicalDiskFormat.RAW, Storage.ProvisioningType.THIN, size, null);
+                    if (disk == null) {
+                        throw new CloudRuntimeException(String.format("Failed 
to provision a %s volume for restore [%s]", poolType, volumeUuid));
+                    }
+                    if (Storage.StoragePoolType.StorPool.equals(poolType)) {
+                        volumePath = disk.getPath();
+                    }
                 }
             } else {
-                if 
(Storage.StoragePoolType.Linstor.equals(volumePool.getPoolType())) {
-                    
storagePoolMgr.connectPhysicalDisk(volumePool.getPoolType(), 
volumePool.getUuid(), volumeUuid, null);
+                if (Storage.StoragePoolType.Linstor.equals(poolType)) {
+                    storagePoolMgr.connectPhysicalDisk(poolType, 
volumePool.getUuid(), volumeUuid, null);
+                } else if (Storage.StoragePoolType.StorPool.equals(poolType)) {
+                    storagePoolMgr.connectPhysicalDisk(poolType, 
volumePool.getUuid(), volumePath, null);

Review Comment:
   if-else can be optimized with switch as you did in below changes



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