This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.18 by this push:
     new 27f23f4f75a linstor: Improve copyPhysicalDisk performance (#9417)
27f23f4f75a is described below

commit 27f23f4f75a4e19e014dcf986c59f2a365d3d716
Author: Rene Peinthor <[email protected]>
AuthorDate: Tue Aug 20 11:17:57 2024 +0200

    linstor: Improve copyPhysicalDisk performance (#9417)
    
    Tell qemu-img that we don't want to use a write cache (we are a block 
device)
    and also specify that we have zeroed devices in most cases.
---
 .../kvm/storage/LinstorStorageAdaptor.java         | 39 +++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git 
a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java
 
b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java
index a3c283699a2..b17c768b96a 100644
--- 
a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java
+++ 
b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java
@@ -54,6 +54,7 @@ import com.linbit.linstor.api.model.ResourceGroupSpawn;
 import com.linbit.linstor.api.model.ResourceMakeAvailable;
 import com.linbit.linstor.api.model.ResourceWithVolumes;
 import com.linbit.linstor.api.model.StoragePool;
+import com.linbit.linstor.api.model.Volume;
 import com.linbit.linstor.api.model.VolumeDefinition;
 
 @StorageAdaptorInfo(storagePoolType=Storage.StoragePoolType.Linstor)
@@ -473,6 +474,40 @@ public class LinstorStorageAdaptor implements 
StorageAdaptor {
         return copyPhysicalDisk(disk, name, destPool, timeout, null, null, 
null);
     }
 
+    /**
+     * Checks if all diskful resource are on a zeroed block device.
+     * @param destPool Linstor pool to use
+     * @param resName Linstor resource name
+     * @return true if all resources are on a provider with zeroed blocks.
+     */
+    private boolean resourceSupportZeroBlocks(KVMStoragePool destPool, String 
resName) {
+        final DevelopersApi api = getLinstorAPI(destPool);
+
+        try {
+            List<ResourceWithVolumes> resWithVols = api.viewResources(
+                    Collections.emptyList(),
+                    Collections.singletonList(resName),
+                    Collections.emptyList(),
+                    Collections.emptyList(),
+                    null,
+                    null);
+
+            if (resWithVols != null) {
+                return resWithVols.stream()
+                        .allMatch(res -> {
+                            Volume vol0 = res.getVolumes().get(0);
+                            return vol0 != null && (vol0.getProviderKind() == 
ProviderKind.LVM_THIN ||
+                                    vol0.getProviderKind() == ProviderKind.ZFS 
||
+                                    vol0.getProviderKind() == 
ProviderKind.ZFS_THIN ||
+                                    vol0.getProviderKind() == 
ProviderKind.DISKLESS);
+                        } );
+            }
+        } catch (ApiException apiExc) {
+            s_logger.error(apiExc.getMessage());
+        }
+        return false;
+    }
+
     @Override
     public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, 
KVMStoragePool destPools, int timeout, byte[] srcPassphrase, byte[] 
destPassphrase, Storage.ProvisioningType provisioningType)
     {
@@ -489,8 +524,10 @@ public class LinstorStorageAdaptor implements 
StorageAdaptor {
         destFile.setFormat(dstDisk.getFormat());
         destFile.setSize(disk.getVirtualSize());
 
+        boolean zeroedDevice = resourceSupportZeroBlocks(destPools, 
LinstorUtil.RSC_PREFIX + name);
+
         try {
-            final QemuImg qemu = new QemuImg(timeout);
+            final QemuImg qemu = new QemuImg(timeout, zeroedDevice, true);
             qemu.convert(srcFile, destFile);
         } catch (QemuImgException | LibvirtException e) {
             s_logger.error(e);

Reply via email to