Bug 1835662

Summary: Allow snapshot creation and blockCopy on read-only drives [rhel-8.2.0.z]
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: Oneata Mircea Teodor <toneata>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: yisun
Severity: unspecified Docs Contact:
Priority: high    
Version: 8.2CC: aliang, bzlotnik, coli, dyuan, hhan, jdenemar, jsuchane, lmen, mtessun, pkrempa, toneata, virt-maint, xuzhang, yalzhang, yisun
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: 8.3Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-6.0.0-17.2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1832204 Environment:
Last Closed: 2020-06-15 14:10: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:
Embargoed:
Bug Depends On: 1832204    
Bug Blocks: 1759933    

Comment 7 yisun 2020-05-25 08:21:59 UTC
tested with libvirt-6.0.0-17.2.module+el8.2.0+6629+3fc0f2c2.x86_64 and result is PASS

1. start a vm with two disks, we'll use vdb to test this, which is a readonly disk
[root@dell-per730-67 ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/vdb.qcow2 1G
Formatting '/var/lib/libvirt/images/vdb.qcow2', fmt=qcow2 size=1073741824 cluster_size=65536 lazy_refcounts=off refcount_bits=16

[root@dell-per730-67 ~]# virsh start vm1
virsDomain vm1 started

[root@dell-per730-67 ~]# virsh domblklist vm1
 Target   Source
--------------------------------------------------------
 vda      /var/lib/libvirt/images/jeos-27-x86_64.qcow2
 vdb      /var/lib/libvirt/images/vdb.qcow2


[root@dell-per730-67 ~]# virsh dumpxml vm1 | awk '/<disk/,/<\/disk/'
    <disk type='file' device='disk' snapshot='no'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/jeos-27-x86_64.qcow2' index='2'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/vdb.qcow2' index='1'/>
      <backingStore/>
      <target dev='vdb' bus='virtio'/>
      <readonly/>
      <alias name='virtio-disk1'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </disk>

2. create external snapshot for it
[root@dell-per730-67 ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/vdb.snap1 1G
Formatting '/var/lib/libvirt/images/vdb.snap1', fmt=qcow2 size=1073741824 cluster_size=65536 lazy_refcounts=off refcount_bits=16


[root@dell-per730-67 ~]# virsh snapshot-create-as vm1 snap1 --disk-only --diskspec vdb,snapshot=external,file=/var/lib/libvirt/images/vdb.snap1 --no-metadata --reuse-external
Domain snapshot snap1 created

3. copy the base image with qemu-img convert
[root@dell-per730-67 ~]# qemu-img convert -f qcow2 /var/lib/libvirt/images/vdb.qcow2 -O qcow2 /tmp/vdb_copy.qcow2

4. do blockcopy --shallow
[root@dell-per730-67 ~]# virsh blockcopy vm1 vdb /tmp/vdb_shallow.qcow2 --shallow --transient-job
Block Copy started

[root@dell-per730-67 ~]# virsh dumpxml vm1 | awk '/<disk/,/<\/disk/'
    <disk type='file' device='disk' snapshot='no'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/jeos-27-x86_64.qcow2' index='2'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/vdb.snap1' index='3'/>
      <backingStore type='file' index='1'>
        <format type='qcow2'/>
        <source file='/var/lib/libvirt/images/vdb.qcow2'/>
        <backingStore/>
      </backingStore>
      <mirror type='file' file='/tmp/vdb_shallow.qcow2' format='qcow2' job='copy' ready='yes'>
        <format type='qcow2'/>
        <source file='/tmp/vdb_shallow.qcow2' index='4'/>
      </mirror>
      <target dev='vdb' bus='virtio'/>
      <readonly/>
      <alias name='virtio-disk1'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </disk>

5. move to the copied target
[root@dell-per730-67 ~]# virsh blockjob vm1 vdb --pivot

[root@dell-per730-67 ~]# virsh dumpxml vm1 | awk '/<disk/,/<\/disk/'
    <disk type='file' device='disk' snapshot='no'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/jeos-27-x86_64.qcow2' index='2'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/tmp/vdb_shallow.qcow2' index='4'/>
      <backingStore type='file' index='1'>
        <format type='qcow2'/>
        <source file='/var/lib/libvirt/images/vdb.qcow2'/>
        <backingStore/>
      </backingStore>
      <target dev='vdb' bus='virtio'/>
      <readonly/>
      <alias name='virtio-disk1'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </disk>

6. do blockcommit to remove the active layer
[root@dell-per730-67 ~]# virsh blockcommit vm1 vdb --top vdb[4] --base vdb[1] --active --pivot
Successfully pivoted

Comment 9 errata-xmlrpc 2020-06-15 14:10: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, 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-2020:2552