Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabled discard option #10077

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

enabled discard option #10077

wants to merge 2 commits into from

Conversation

slavkap
Copy link
Contributor

@slavkap slavkap commented Dec 10, 2024

Description

Enable the discard option for virtio-blk and virtio-scsi devices for volumes on StorPool storage

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

How Has This Been Tested?

manually tested with different controllers and UEFI legacy/secured
deploy a VM
attach volume

Enable the discard option for virtio-blk and virtio-scsi devices for
volumes on StorPool storage
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 16.06%. Comparing base (c94d0ab) to head (63e0cd6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ud/hypervisor/kvm/storage/StorPoolStoragePool.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10077      +/-   ##
============================================
- Coverage     16.06%   16.06%   -0.01%     
- Complexity    12862    12863       +1     
============================================
  Files          5641     5642       +1     
  Lines        493791   493856      +65     
  Branches      59858    59860       +2     
============================================
+ Hits          79318    79326       +8     
- Misses       405691   405749      +58     
+ Partials       8782     8781       -1     
Flag Coverage Δ
uitests 4.02% <ø> (ø)
unittests 16.90% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DaanHoogland DaanHoogland added this to the 4.21.0 milestone Dec 10, 2024
Copy link
Contributor

@BryanMLima BryanMLima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLGTM

rearrange imports
@DaanHoogland
Copy link
Contributor

Code looks ok, but we need to rely on your testing, @slavkap !

Copy link
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM.

minor: @slavkap would something like this improve readability?

--- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStoragePool.java
+++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStoragePool.java
@@ -16,11 +16,13 @@
 // under the License.
 package com.cloud.hypervisor.kvm.storage;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
 
+import com.cloud.hypervisor.kvm.resource.LibvirtVMDef;
 import com.cloud.storage.Storage;
 import com.cloud.storage.Storage.StoragePoolType;
 
@@ -35,6 +37,11 @@ public class StorPoolStoragePool implements KVMStoragePool {
     private String _sourceDir;
     private String _localPath;
 
+    private static final List<LibvirtVMDef.DiskDef.DiskBus> supportedBusTypes = Arrays.asList(
+            LibvirtVMDef.DiskDef.DiskBus.VIRTIO,
+            LibvirtVMDef.DiskDef.DiskBus.SCSI
+    );
+
     public StorPoolStoragePool(String uuid, String host, int port, StoragePoolType storagePoolType, StorageAdaptor storageAdaptor) {
         _uuid = uuid;
         _sourceHost = host;
@@ -166,4 +173,11 @@ public class StorPoolStoragePool implements KVMStoragePool {
     public Map<String, String> getDetails() {
         return null;
     }
+
+    public void customizeLibvirtDiskDef(LibvirtVMDef.DiskDef disk) {
+        if (!supportedBusTypes.contains(disk.getBusType())) {
+            return;
+        }
+        disk.setDiscard(LibvirtVMDef.DiskDef.DiscardType.UNMAP);
+    }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants