Bug 1929519

Summary: libvirt should utilize 'qemu-img convert' progress report, instead of own computations
Product: Red Hat Enterprise Linux 9 Reporter: Christian Horn <chorn>
Component: libvirtAssignee: Virtualization Maintenance <virt-maint>
libvirt sub component: Storage QA Contact: zhoujunqin <juzhou>
Status: CLOSED WONTFIX Docs Contact:
Severity: medium    
Priority: low CC: coli, crobinso, jsuchane, juzhou, kwolf, lmen, mprivozn, pkrempa, tzheng, virt-maint, xuwei, xuzhang, yoguma
Version: 9.0Keywords: Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1935810 (view as bug list) Environment:
Last Closed: 2022-08-17 07:28:35 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:
Embargoed:
Bug Depends On:    
Bug Blocks: 1935810    

Description Christian Horn 2021-02-17 04:45:54 UTC
Description of problem:
libvirt does own calculations of the progress of
'qemu-img convert -f qcow2 -O qcow2 -o preallocation=falloc,compat=1.1,lazy_refcounts'
operations.  That fails with xfs' preallocations.  It seems like utilizing qemu-img provided
progress counter should fix this.

Version-Release number of selected component (if applicable):
libvirt-6.0.0-28.module+el8.3.0+7827+5e65edd7 (from rhel8.3GA),
but the issue is also in rhel8.4 libvirt versions

How reproducible:
always

Steps to Reproduce:
https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c6 and
https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c7 should be usable.

Additional info, background:
- A partner opened bz1877163,
  "The progress bar of the "virt-clone --nonsparse" command shows the progress rate exceeding 100%"
- The flow seen in that bz seems to be (refer to https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c16 ff)
  - virt-clone calls into libvirt APIs to clone the disk
  - libvirt calls:
    qemu-img convert -f qcow2 -O qcow2 -o preallocation=falloc,compat=1.1,lazy_refcounts [..]
  - virt-clone then queries libvirt API in a loop to get the "disk size",
    compares against requested disk size and computes progress
  - libvirt is by itself computing progress based on xfs details.
    xfs is doing preallocation
    ( https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c19 ), rendering
    libvirts calculation incorrect
- From the research in bz1877163, it seems like libvirt could utilize
  the progress data from qemu-img, and simply make that available
  ( https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c38 )

Comment 1 Christian Horn 2021-02-17 08:41:42 UTC
Maybe virt-clone is the component here which needs to be fixed instead
of libvirt, could the libvirt team please confirm?

Comment 2 Jaroslav Suchanek 2021-02-18 15:19:52 UTC
(In reply to Christian Horn from comment #1)
> Maybe virt-clone is the component here which needs to be fixed instead
> of libvirt, could the libvirt team please confirm?

Yes, we need to fix both components.

Comment 3 Christian Horn 2021-02-19 00:21:12 UTC
(In reply to Jaroslav Suchanek from comment #2)
> (In reply to Christian Horn from comment #1)
> > Maybe virt-clone is the component here which needs to be fixed instead
> > of libvirt, could the libvirt team please confirm?
> 
> Yes, we need to fix both components.

Thanks.  I think virt-clone is part of virt-install, component is
virt-manager.  Do we need a further bz then for virt-manager?

Comment 4 Jaroslav Suchanek 2021-03-05 15:51:24 UTC
(In reply to Christian Horn from comment #3)
> (In reply to Jaroslav Suchanek from comment #2)
> > (In reply to Christian Horn from comment #1)
> > > Maybe virt-clone is the component here which needs to be fixed instead
> > > of libvirt, could the libvirt team please confirm?
> > 
> > Yes, we need to fix both components.
> 
> Thanks.  I think virt-clone is part of virt-install, component is
> virt-manager.  Do we need a further bz then for virt-manager?

I cloned it to bug 1935810.

Thanks.

Comment 5 Michal Privoznik 2021-06-29 08:41:32 UTC
So what happens here, is that virt-clone calls virStorageVolCreateXMLFrom() passing in the original disk image. This instructs libvirt to run 'qemu-img convert'. Meanwhile, virt-clone calls virStorageVolGetInfo() every second to fetch new allocation size. As such, the API indeed returns correct numbers but those are not interpreted correctly (the file allocation on XFS does work in chunks and may temporarily exceed desired file size; I've been meeting this problem when implementing sparse streams - see bug 1282859#c15). I will let others to express their thoughts, but meanwhile this is low priority.

Comment 6 John Ferlan 2021-09-09 18:27:44 UTC
Bulk update: Move RHEL-AV bugs to RHEL8.

Since the cloned from bug is a virt-manager related and this bug has a Fujitsu relationship, leave this on RHEL8. If resolution/testing is needed on RHEL9, then a RHEL9 clone can be created.

Comment 8 RHEL Program Management 2022-08-17 07:28:35 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.

Comment 9 Christian Horn 2022-08-19 06:59:33 UTC
Hm.. this here is the rhel9 clone of bz1877163 which our partner
reported for rhel8.
Seems like this one here got closed without being picked up.

So if the issue is in rhel9, while it's fixed now in rhel8, then
customers will see a regression when upgrading.

bz1877163 (rhel8) was solved by 
https://access.redhat.com/errata/RHSA-2021:4191 .
I looked at the changelog, but found no reference to bz1877163 .
That errata has libvirt-6.0.0-37.module+el8.5.0+12162+40884dd2.src.rpm.
https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c65 mentions a patch,
but I found no traces of that in libvirt-6.0.0-37.module+el8.5.0+12162+40884dd2.src.rpm .
The patch is probably in though, as QA did sanity verification, in other words 
found the patch.

I will consult with the primary TAM on further steps here,
setting needinfo so this is not forgotten.

Comment 10 Peter Krempa 2022-08-22 10:14:58 UTC
Note that libvirt didn't in any version change how the progress is being reported. I'm not sure how the virt-clone bug was solved, but it was not by adopting a different method of counting progress by libvirt.

Comment 11 Kevin Wolf 2022-08-25 10:06:52 UTC
From my comment at https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c38:

> We can backport the extent size hint which will make the accidental
> approximation match reality better, but it is not a proper bug fix. It only
> hides the bug until something else changes the preallocation strategy again
> (or until you want really precise information instead of just an
> approximation).

This is what we ended up doing. The patch backported for the RHEL 8 bug is already part of RHEL 9.0 due to the rebase to a newer upstream version of QEMU.

Maybe QE could test that the behaviour is still the same in 9.1 as in 8.5?

Comment 12 zhoujunqin 2022-08-29 12:10:07 UTC
(In reply to Kevin Wolf from comment #11)
> From my comment at https://bugzilla.redhat.com/show_bug.cgi?id=1877163#c38:
> 
> > We can backport the extent size hint which will make the accidental
> > approximation match reality better, but it is not a proper bug fix. It only
> > hides the bug until something else changes the preallocation strategy again
> > (or until you want really precise information instead of just an
> > approximation).
> 
> This is what we ended up doing. The patch backported for the RHEL 8 bug is
> already part of RHEL 9.0 due to the rebase to a newer upstream version of
> QEMU.
> 
> Maybe QE could test that the behaviour is still the same in 9.1 as in 8.5?

Hi Kevin,

Packages version:
qemu-kvm-7.0.0-12.el9.x86_64
libvirt-8.5.0-5.el9.x86_64
virt-install-4.0.0-1.el9.noarch
virt-manager-4.0.0-1.el9.noarch


Steps:

1. Prepare a shutoff VM whose filesystem is XFS.

# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Aug  3 03:14:57 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=6ab6de88-f76d-4def-8f1c-188c7b108d4c /boot                   xfs     defaults        0 0
UUID=82EB-0312          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
/dev/mapper/rhel-swap   none                    swap    defaults        0 0



# qemu-img info /var/lib/libvirt/images/GuestOne.qcow2 
image: /var/lib/libvirt/images/GuestOne.qcow2
file format: qcow2
virtual size: 20 GiB (21474836480 bytes)
disk size: 1.43 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: true
    refcount bits: 16
    corrupt: false
    extended l2: false



2. Clone the VM.


# virt-clone --file /var/lib/libvirt/images/GuestOne-clone.qcow2 --original GuestOne --name GuestOne-clone  --nonsparse
Allocating 'GuestOne-clone.qcow2'                                            |  20 GB  00:00:12 !!! 

Clone 'GuestOne-clone' created successfully.

# qemu-img info /var/lib/libvirt/images/GuestOne-clone.qcow2 
image: /var/lib/libvirt/images/GuestOne-clone.qcow2
file format: qcow2
virtual size: 20 GiB (21474836480 bytes)
disk size: 20 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: true
    refcount bits: 16
    corrupt: false
    extended l2: false


Test result: During the cloning progress, the process bar is 100% all the time.

And Core has given feedback for this behavior in https://bugzilla.redhat.com/show_bug.cgi?id=1935810#c6 

@Kevin, Please have a look at my test, thanks.

@Core, this has been closed as WONFIX, and how about your opinion on the blocked bug 1935810, thanks.

Comment 13 Cole Robinson 2022-09-07 14:00:32 UTC
My opinion on bug 1935810 hasn't changed. simplest 'fix' I can think of is to disable progress reporting in the --nonsparse case. But we would be trading 'virt-clone progress pegged at 100%' for 'virt-clone not reporting progress' so it's not some great improvement.