Repository navigation
Conversation
JoaoJandre
left a comment
There was a problem hiding this comment.
CLGTM, did not test it
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.20 #14247 +/- ##
============================================
+ Coverage 16.38% 16.42% +0.03%
- Complexity 13614 13661 +47
============================================
Files 5669 5669
Lines 501532 501661 +129
Branches 60922 60948 +26
============================================
+ Hits 82153 82373 +220
+ Misses 410172 410057 -115
- Partials 9207 9231 +24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if (disk.getDeviceType() == DeviceType.DISK) { | ||
| if (disk.getBusType() == DiskDef.DiskBus.SCSI) { | ||
| busT = DiskDef.DiskBus.SCSI; | ||
| } else if (disk.getBusType() == DiskDef.DiskBus.VIRTIOBLK) { |
There was a problem hiding this comment.
can this ever match now? the running vm reports these disks back as plain virtio, so a disk added this way still loses discard
There was a problem hiding this comment.
You are right, it can't.
The running VM reports these only as plain virtio. The method goes through getAttachDiskBusType(), which falls back to rootDiskController, so the disk still gets discard (tested).
SO i just removed the dead checks.
There was a problem hiding this comment.
makes sense, the attach path following the root controller keeps discard on, so dropping the dead checks is fine
|
I have some concerns about honoring "virtio-blk" as a separate disk controller option. In libvirt, "virtio" is the disk bus, and the corresponding device is already a VirtIO block device ("virtio-blk"). This is similar to how a VirtIO NIC is represented by a "virtio" interface model, corresponding to a "virtio-net" device. As a result, the existing CloudStack "virtio" disk controller option already maps to a VirtIO block device. With this change, "virtio" and "virtio-blk" would effectively expose the same device model, with the main difference being that "virtio-blk" enables "discard='unmap'". I think this could be confusing for users, because the controller option appears to describe the device type, while it also implicitly controls discard behavior. Could we instead keep "virtio" as the controller option and handle discard/unmap as a separate configuration? This would make the distinction between the disk device model and its discard capability clearer. |
Alright, I will take a look at how complicated it would be. I assume you would also want to get rid of |
thanks. |
…ller
Discard on KVM disks could only be had implicitly: SCSI and Linstor disks get
discard='unmap', every other disk keeps libvirt's default 'ignore', so a guest's
TRIM never reaches thin storage such as Ceph RBD. The virtio-blk controller
option was meant to provide it for virtio disks, but libvirt has no such bus
('virtio' already is a virtio-blk device), so a VM using it could not start.
- New KVM VM detail disk.discard (unmap|ignore). It is applied to every disk
when the VM starts and when a disk is attached; without it the disks keep
their current defaults. 'unmap' is not set on IDE disks with a QEMU that has
the IDE discard bug.
- virtio-blk is no longer offered as a disk controller. A VM or template that
still has it set gets a virtio disk, as before the option existed.
7233d17 to
3726c40
Compare
I reworked the feature |
thanks @calvix for the update. it looks good to me overall. @JoaoJandre @Damans227 could you re-review this PR ? |
|
thanks @calvix, the rework looks good to me |
Description
Discard on KVM disks can only be enabled implicitly today: SCSI disks and Linstor RAW disks get
discard='unmap', every other disk keeps libvirt's defaultdiscard='ignore'. A guest's TRIM on a virtio disk never reaches the storage, so on thin storage such as Ceph RBD deleted data keeps occupying the pool.The
virtio-blkdisk controller (#10229, for #9299 "Virtio-blk support fstrim") was meant to cover this, but libvirt has novirtio-blkbus,virtioalready is a virtio-blk device, so a VM withrootDiskController=virtio-blkcan't start:This PR first made
virtio-blkusable as a controller that turns on discard. As discussed in the review, it now takes a different approach.discardis a separate VM setting instead of being implied by a controller name, and thevirtio-blkoption, which never worked, is removed.Changes
disk.discard,unmaporignore. It is applied to every disk of the VM when it starts and when a disk is attached (the server passes it in the attach details, likeio.policy). Without the detail the disks keep their current defaults, so nothing changes for existing VMs.ignorealso turns off the SCSI / Linstor default.unmapis not set on IDE disks when QEMU has the IDE discard bug (isQemuDiscardBugFree, QEMU < 7.0), same as the Linstor case.disk.discardis returned bylistDetailOptionsfor KVM, and dropped on deploy for other hypervisors likeiothreadsandio.policy.virtio-blkis no longer offered as a root or data disk controller (listDetailOptions, template UI) and theVIRTIOBLKbus is gone. A VM or template that still hasvirtio-blkset gets a virtio disk, so it starts instead of failing.Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
How Has This Been Tested?
Tested on a KVM cluster with Ceph RBD primary storage (Ubuntu 24.04 hosts), with this change ported to 4.23:
discard, as before;disk.discard=unmap:discard='unmap'on root and data disks;unmapas before; SCSI withdisk.discard=ignore: no discard;on): no discard, and a warning in the agent log;rootDiskController=virtio-blk(previously failed to start with the error above): starts with a virtio disk, no discard; withdisk.discard=unmapadded it getsunmap;dataDiskController=virtio-blkgives virtio data disks.unmapthe RBD image shrank from 1.0 GiB to 48 MiB of used space (both a hot-attached disk and a disk present at start). Without the detail it stays at 1.0 GiB: the guest reports the trim, but QEMU drops it.updateVirtualMachineaddingdisk.discard=unmapto a stopped VM that hasrootDiskController=virtio-blkworks, so existing virtio-blk VMs can be moved to the detail.listDetailOptionsreturnsdisk.discardwithunmapandignore, and the controller lists no longer containvirtio-blk; the UI no longer offers it.