<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Hello,
<div><br>
</div>
<div>I am attempting to enable discard support on the virtio-blk device on a QEMU VM</div>
<div>however it isn't working. My understanding is that this is enabled in QEMU >=</div>
<div>4.0, so I am not sure why this isn't working:</div>
<div><br>
</div>
<div>Host OS: Ubuntu 20.04 (kernel 5.4.0)</div>
<div>Guest OS: Ubuntu 18.04 (kernel 4.15.0)</div>
<div><br>
</div>
<div>Guest config:</div>
<div><os></div>
<div>  <type arch='x86_64' machine='pc-q35-4.2'>hvm</type></div>
<div></os></div>
<div><disk type='file' device='disk'></div>
<div>  <driver name='qemu' type='qcow2' discard='unmap'/></div>
<div>  <source file='/var/lib/libvirt/images/myvm.qcow2' index='1'/></div>
<div>  <backingStore/></div>
<div>  <target dev='vda' bus='virtio'/></div>
<div>  <alias name='virtio-disk0'/></div>
<div>  <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/></div>
<div></disk></div>
<div><br>
</div>
<div>What are the values for machine type that will support discard on virtio-blk?</div>
<div>Anything 4.0 or greater (e.g. would pc-i440fx-4.0 work too)?</div>
<div><br>
</div>
<div>I can see from the host's perspective that the guest appears to have discard</div>
<div>enabled because the following command shows "discard = true":</div>
<div># virsh qemu-monitor-command myvm --hmp info qtree | grep discard</div>
<div><br>
</div>
<div>yet inside the VM, even with the "discard" mount option set:</div>
<div> # for f in /sys/block/vda/queue/discard_*; do echo $f; cat $f; done</div>
<div>/sys/block/vda/queue/discard_granularity</div>
<div>0</div>
<div>/sys/block/vda/queue/discard_max_bytes</div>
<div>0</div>
<div>/sys/block/vda/queue/discard_max_hw_bytes</div>
<div>0</div>
<div>/sys/block/vda/queue/discard_zeroes_data</div>
<div>0</div>
<div><br>
</div>
<div>Are the virtio drivers in the guest kernel too old to support discard on</div>
<div>virtio-blk? Or is something else missing?</div>
<div><br>
</div>
<div>Thanks,</div>
<div><br>
</div>
Andrew<br>
</div>
</body>
</html>