Hello,

I am attempting to enable discard support on the virtio-blk device on a QEMU VM
however it isn't working. My understanding is that this is enabled in QEMU >=
4.0, so I am not sure why this isn't working:

Host OS: Ubuntu 20.04 (kernel 5.4.0)
Guest OS: Ubuntu 18.04 (kernel 4.15.0)

Guest config:
<os>
  <type arch='x86_64' machine='pc-q35-4.2'>hvm</type>
</os>
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' discard='unmap'/>
  <source file='/var/lib/libvirt/images/myvm.qcow2' index='1'/>
  <backingStore/>
  <target dev='vda' bus='virtio'/>
  <alias name='virtio-disk0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</disk>

What are the values for machine type that will support discard on virtio-blk?
Anything 4.0 or greater (e.g. would pc-i440fx-4.0 work too)?

I can see from the host's perspective that the guest appears to have discard
enabled because the following command shows "discard = true":
# virsh qemu-monitor-command myvm --hmp info qtree | grep discard

yet inside the VM, even with the "discard" mount option set:
 # for f in /sys/block/vda/queue/discard_*; do echo $f; cat $f; done
/sys/block/vda/queue/discard_granularity
0
/sys/block/vda/queue/discard_max_bytes
0
/sys/block/vda/queue/discard_max_hw_bytes
0
/sys/block/vda/queue/discard_zeroes_data
0

Are the virtio drivers in the guest kernel too old to support discard on
virtio-blk? Or is something else missing?

Thanks,

Andrew

Reply via email to