Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.

Bug 1986509

Summary: libvirt does not pass discard flag to copy-on-read blockdev layers
Product: Red Hat Enterprise Linux 9 Reporter: Richard W.M. Jones <rjones>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED CURRENTRELEASE QA Contact: Han Han <hhan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: jdenemar, lmen, mxie, pkrempa, tzheng, virt-maint, xuzhang
Target Milestone: betaKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-7.6.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-12-07 21:57:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version: 7.6.0
Embargoed:
Bug Depends On:    
Bug Blocks: 910269    

Description Richard W.M. Jones 2021-07-27 17:42:23 UTC
Description of problem:

The long description is here:
https://listman.redhat.com/archives/libguestfs/2021-July/msg00067.html

The short description is: When we use the copy_on_read="on"
and discard="unmap" attributes together on a <disk/> element,
libvirt does not set up blockdev correctly, so the unmap
flag is dropped.  This results in trim messages being
dropped in the copy-on-read layer.

Version-Release number of selected component (if applicable):

libvirt-7.5.0-1.el9

How reproducible:

100%

Steps to Reproduce:

See https://listman.redhat.com/archives/libguestfs/2021-July/msg00067.html
for a full reproducer.

Peter has suggested this patch to libvirt:
https://gitlab.com/pipo.sk/libvirt/-/commit/13d30ec012b258105678356e504c0f5e79881956

I tested Peter's patch and it works for me.

Comment 1 Richard W.M. Jones 2021-07-28 09:41:19 UTC
Upstream fix:
https://listman.redhat.com/archives/libvir-list/2021-July/thread.html#00823

Comment 2 Peter Krempa 2021-07-28 13:22:05 UTC
Fixed upstream:

commit dc0b9c8376afb88eb3a3156d7e991d29d9c196a8
Author: Peter Krempa <pkrempa>
Date:   Tue Jul 27 19:12:09 2021 +0200

    qemu: block: Pass discard requests through the copy-on-read block filter
    
    We need to pass the 'trim' requests through the copy-on-read filter so
    if a user configures a discard policy on the disk the requests get
    through to the appropriate format layer in the blockdev tree.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1986509
    Reported-by: Richard W.M. Jones <rjones>
    Tested-by: Richard W.M. Jones <rjones>
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Daniel P. Berrangé <berrange>
    Reviewed-by: Michal Privoznik <mprivozn>
    Reviewed-by: Richard W.M. Jones <rjones>

v7.6.0-rc1-4-gdc0b9c8376

Comment 3 Han Han 2021-08-02 02:24:41 UTC
Reproduced on libvirt-7.5.0-1.module+el8.5.0+11664+59f87560.x86_64:
For an VM with XML:
<domain>
...
  <disk>
  ...
      <driver name='qemu' type='qcow2' copy_on_read='on' discard='unmap'/>
  ...
  </disk>
...
</domain>


Extract its qemu cmdline by `virsh domxml-to-native --domain VM qemu-argv`
The qemu cmdline of -blockdev is:
-blockdev '{"driver":"gluster","volume":"gv0","path":"hhan.qcow2","server":[{"type":"inet","host":"10.0.148.14","port":"24007"}],"debug":4,"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' -blockdev '{"node-name":"libvirt-1-format","read-only":false,"discard":"unmap","driver":"qcow2","file":"libvirt-1-storage"}' -blockdev '{"driver":"copy-on-read","node-name":"libvirt-CoR-vda","file":"libvirt-1-format"}'

The "discard":"unmap" is not in the copy-on-read layer.


The libvirt upstream has covered this unit test.

Comment 6 Han Han 2021-08-23 02:11:50 UTC
Tested on libvirt-7.6.0-2.el9.x86_64 as comment3:
Results:
-blockdev {"node-name":"libvirt-1-format","read-only":false,"discard":"unmap","driver":"qcow2","file":"libvirt-1-storage","backing":null} -blockdev {"driver":"copy-on-read","node-name":"libvirt-CoR-sda","file":"libvirt-1-format","discard":"unmap"}

"discard":"unmap" is in copy-on-read blockdev node.