Bug 1977155

Summary: Snapshot deletion fails for shutoff VM when the disk is using the pool/volume format for local directories.
Product: Red Hat Enterprise Linux 9 Reporter: YunmingYang <yunyang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
libvirt sub component: General QA Contact: yisun
Status: CLOSED ERRATA Docs Contact:
Severity: medium    
Priority: unspecified CC: jdenemar, kkoukiou, lmen, mpitt, skobyda, virt-maint, wshi, xchen, xuzhang, ymao
Version: 9.0Keywords: AutomationTriaged, Triaged
Target Milestone: beta   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-7.7.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-17 12:45:04 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.7.0
Embargoed:

Description YunmingYang 2021-06-29 05:30:26 UTC
Description of problem:
For a shutoff VM, attach disk by 'virsh attach-device ${domain} ${device_xml}'

And here is the xml of device:
<disk type="volume" device="disk">
    <driver name="qemu" type="qcow2" cache="default"/>
    <source volume="${volume_name}" pool="${pool_name}"/>
    <target dev="vda" bus="virtio"/>
</disk>

Then create a snapshot for the VM with this disk by "virsh snapshot-create-as ${domain_name} ${snapshot_name}"

And then, try to delete this snapshot by "virsh snapshot-delete ${domain_name} --snapshotname ${snapshot_name}". 

And there will be an error like "
error: Failed to delete snapshot ${snapshot_name}
error: Requested operation is not valid: can't manipulate inactive snapshots of disk 'vda'
"


Version-Release number of selected components (if applicable):
libvirt-libs-7.4.0-1.el9.x86_64
libvirt-daemon-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-core-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-disk-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-iscsi-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-iscsi-direct-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-logical-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-mpath-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-scsi-7.4.0-1.el9.x86_64
libvirt-daemon-driver-interface-7.4.0-1.el9.x86_64
libvirt-daemon-driver-nwfilter-7.4.0-1.el9.x86_64
libvirt-daemon-driver-secret-7.4.0-1.el9.x86_64
libvirt-glib-4.0.0-2.el9.x86_64
libvirt-dbus-1.4.0-4.el9.x86_64
python3-libvirt-7.3.0-1.el9.x86_64
libvirt-daemon-driver-network-7.4.0-1.el9.x86_64
libvirt-daemon-driver-nodedev-7.4.0-1.el9.x86_64
libvirt-client-7.4.0-1.el9.x86_64
libvirt-daemon-driver-qemu-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-rbd-7.4.0-1.el9.x86_64
libvirt-daemon-driver-storage-7.4.0-1.el9.x86_64
libvirt-daemon-kvm-7.4.0-1.el9.x86_64


How reproducible:
100%


Steps to Reproduce:
1 Prepare a shutoff VM
2 attach disk by 'virsh attach-device --persistent ${domain_name} ${xml_path}'
  and here is the xml:
  <disk type="volume" device="disk">
    <driver name="qemu" type="qcow2" cache="default"/>
    <source volume="${volume_name}" pool="${pool_name}"/>
    <target dev="vda" bus="virtio"/>
  </disk>
3 Create a snapshot by "virsh snapshot-create-as ${domain_name} ${snapshot_name}"
4 Delete the snapshot by "virsh snapshot-delete ${domain_name} ${snapshot_name}"


Actual results:
1 After step 4, there will be an error "
error: Failed to delete snapshot ${snapshot_name}
error: Requested operation is not valid: can't manipulate inactive snapshots of disk 'vda'
"

Expected results: 
1 After step 4, The snapshot can be deleted


Additional info:

Comment 1 YunmingYang 2021-06-29 06:20:08 UTC
Also here is the pool xml:
<pool type='dir'>
  <name>images</name>
  <uuid>b7a629b9-c21e-4367-bc9d-3045d29799f7</uuid>
  <capacity unit='bytes'>75125227520</capacity>
  <allocation unit='bytes'>6457651200</allocation>
  <available unit='bytes'>68667576320</available>
  <source>
  </source>
  <target>
    <path>/var/lib/libvirt/images</path>
    <permissions>
      <mode>0711</mode>
      <owner>0</owner>
      <group>0</group>
      <label>system_u:object_r:virt_image_t:s0</label>
    </permissions>
  </target>
</pool>

Comment 2 Peter Krempa 2021-08-25 13:50:59 UTC
Fixed upstream by:

commit 97e4fb3c106fe38c1440e762014390a9821a4d69
Author: Peter Krempa <pkrempa>
Date:   Fri Jul 2 16:00:05 2021 +0200

    qemu: snapshot: Translate 'volume' disks before attempting offline snapshot manipulation
    
    When the VM is inactive the 'virStorageSource' struct doesn't have the
    necessary data pointing to the actual storage. This is a problem for
    inactive snapshot operations on VMs which use disk type='volume'.
    
    Add the translation steps for reversion and deletion of snapshots.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1977155
    Resolves: https://gitlab.com/libvirt/libvirt/-/issues/202
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

v7.6.0-310-g97e4fb3c10

Comment 3 yisun 2021-09-29 08:05:44 UTC
[root@dell-per740xd-25 ~]# rpm -qa | grep ^libvirt-7
libvirt-7.7.0-3.el9.x86_64

1. having a shutoff vm with disk type = 'volume'
[root@dell-per740xd-25 ~]# virsh vol-list images-1
 Name                          Path
----------------------------------------------------------------------------------------------------
...
 vda.qcow2                     /var/lib/avocado/data/avocado-vt/images/vda.qcow2


[root@dell-per740xd-25 ~]# virsh dumpxml vm1 | awk  '/<disk/,/<\/disk/'
    <disk type='volume' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source pool='images-1' volume='vda.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>

[root@dell-per740xd-25 ~]# virsh domstate vm1
shut off

2. create internal snapshot for it
[root@dell-per740xd-25 ~]# virsh snapshot-create-as vm1 s1
Domain snapshot s1 created	Snapshot created succesfully and can be found in qcow2 file

[root@dell-per740xd-25 ~]# qemu-img info /var/lib/avocado/data/avocado-vt/images/vda.qcow2 | grep s1 -B2
Snapshot list:
ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT
1         s1                    0 B 2021-09-29 03:44:52 00:00:00.000          0

3. delete the snapshot
[root@dell-per740xd-25 ~]# virsh snapshot-delete vm1 s1
Domain snapshot s1 deleted

Comment 6 errata-xmlrpc 2022-05-17 12:45:04 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