Bug 2039131

Summary: The metadata of snapshot isn't discarded when creating with --no-metadata option
Product: Red Hat Enterprise Linux 9 Reporter: Meina Li <meili>
Component: libvirtAssignee: Peter Krempa <pkrempa>
libvirt sub component: Storage QA Contact: liang cong <lcong>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: jdenemar, lmen, pkrempa, virt-maint, weizhan, xuzhang, yisun
Version: 9.0Keywords: Automation, Regression, Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-8.0.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-17 12:46:17 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: 8.0.0
Embargoed:

Description Meina Li 2022-01-11 03:09:48 UTC
Description of problem:
The metadata of snapshot isn't discarded when creating with --no-metadata option

Version-Release number of selected component (if applicable):
libvirt-8.0.0-0rc1.1.el9.x86_64
qemu-kvm-6.2.0-3.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Prepare a running guest.
# virsh domstate lmn
running

2. Create a snapshot with --no-metadata.
# virsh snapshot-create-as lmn s1 --disk-only --no-metadata --diskspec vda,snapshot=external,file=/var/lib/libvirt/images/test.s1
Domain snapshot s1 created

3. Check the snapshot list.
# virsh snapshot-list lmn
 Name   Creation Time               State
---------------------------------------------------
 s1     2022-01-10 21:10:41 -0500   disk-snapshot

Actual results:
In step 3, the metadata of the snapshot isn't discarded.

Expected results:
There's no snapshot in snapshot list

Additional info:
Cannot reproduce in libvirt-7.10.0-1.el9.x86_64

Comment 1 Peter Krempa 2022-01-12 15:05:47 UTC
Fixed upstream:

commit 164aba8c4aef8094e151f593baf95421feb6dc5f
Author: Peter Krempa <pkrempa>
Date:   Tue Jan 11 10:28:45 2022 +0100

    qemuSnapshotCreate: Don't insert snapshot into list with VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA
    
    Our approach to snapshots without metadata was to insert them to the
    snapshot list and then later remove them from the list when the flag is
    present.
    
    This quirky logic was broken in a recent refactor of the snapshot code
    causing that the snapshot stayed inserted in the snapshot list.
    
    Recent refactor of the snapshot code didn't faithfully relocate this
    logic to the new function.
    
    Rather than attempting to restore the quirky logic of adding and then
    removing the object, don't add the snapshot into the list at all when
    the user doesn't want metadata.
    
    We achieve this by creating a temporary 'virDomainMomentObj' wrapper
    which is not inserted into the list and using that instead of calling
    virDomainSnapshotAssignDef.
    
    Fixes: 9bad0fb809b
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2039131
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Michal Privoznik <mprivozn>

v8.0.0-rc2-3-g164aba8c4a

Comment 2 liang cong 2022-01-13 06:04:47 UTC
Preverify on:
libvirt: v8.0.0-rc2-3-g164aba8c4a
qemu-6.2.0-2.fc36.x86_64
qemu-kvm-6.2.0-2.fc36.x86_64

steps:
1. Prepare a running guest.
# virsh domstate vm2
running


2. Create a snapshot with --no-metadata.
# virsh snapshot-create-as vm2 s1 --disk-only --no-metadata --diskspec vda,snapshot=external,file=/var/lib/libvirt/images/test.s1
Domain snapshot s1 created

3. Check the snapshot list, found there's no snapshot in snapshot list
# virsh snapshot-list vm2
 Name   Creation Time   State
-------------------------------

4. Create another snapshot with --no-metadata.
# virsh snapshot-create-as vm2 s2 --no-metadata
Domain snapshot s2 created

5. Check the snapshot list, found there's no snapshot in snapshot list
# virsh snapshot-list vm2
 Name   Creation Time   State
-------------------------------

Comment 5 liang cong 2022-01-25 07:35:40 UTC
Verified on libvirt-8.0.0-1.el9.x86_64

# rpm -q libvirt qemu-kvm
libvirt-8.0.0-1.el9.x86_64
qemu-kvm-6.2.0-4.el9.x86_64

# virsh snapshot-create-as vm1 s1 --no-metadata
Domain snapshot s1 created

# virsh snapshot-list vm1
 Name   Creation Time   State
-------------------------------


# qemu-img info /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.qcow2  -U
image: /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 1.5 GiB
cluster_size: 65536
Snapshot list:
ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT
1         s1                452 MiB 2022-01-18 02:07:03 00:08:45.311           
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false



# virsh snapshot-create-as vm1 s1 --no-metadata --disk-only
Domain snapshot s1 created

# virsh snapshot-list vm1
 Name   Creation Time   State
-------------------------------

# qemu-img info /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.s1  -U --backing-chain
image: /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.s1
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 1.51 MiB
cluster_size: 65536
backing file: /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.qcow2
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

image: /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 1.04 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false


# virsh snapshot-create-as vm1 s1 --disk-only --no-metadata --diskspec vda,snapshot=external,file=/tmp/test.s1
Domain snapshot s1 created

# virsh snapshot-list vm1
 Name   Creation Time   State
-------------------------------

# qemu-img info /tmp/test.s1 
image: /tmp/test.s1
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: /var/lib/libvirt/images/RHEL-8.6-x86_64-latest.raw
backing file format: raw
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

Comment 7 errata-xmlrpc 2022-05-17 12:46:17 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (new packages: libvirt), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:2390